Skip to content

[Bug]: Plotting numpy.array of dtype float32 with pyplot.imshow and specified colors.LogNorm produces wrong colors #28731

Closed as not planned
@faressc

Description

@faressc

Bug summary

Plotting an equal numpy.array of dtype float64 and float32 with pyplot.imshow and a defined colors.LogNorm as norm will produce different colors in the resulting image.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np

norm = colors.LogNorm(vmin=1e-10, vmax=1)
test_numpy = np.array([[1e-4]])
test_numpy_32 = np.array([[1e-4]], dtype=np.float32)

for test in [test_numpy, test_numpy_32]:
    plt.imshow(test, norm=norm)
    plt.title(f"numpy array of dtype: {test.dtype}")
    plt.colorbar()
    plt.show()

Actual outcome

The resulting plot for the dtype float64 numpy.array looks like this:

float64

and the plot for the dtype float32 numpy.array looks like this:

float32

Expected outcome

I would expect both outputs to have the same color.

Additional information

No response

Operating system

Arch

Matplotlib Version

3.9.1.post1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.12.4

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions