Incorrect & inconsistent coloring in .imshow() with LogNorm · Issue #19748 · matplotlib/matplotlib · GitHub
Skip to content

Incorrect & inconsistent coloring in .imshow() with LogNorm #19748

Description

@mdmisch

Bug report

Bug summary

.imshow() with LogNorm produces incorrect and inconsistent coloring.

Code for reproduction

In this example the same array was plotted twice. The first .imshow() call plots the whole array. The following two plot two halves of the same array separately.

The mpl_toolkits is used only to fix axes and colorbar positioning; problems with coloring remain even without it.

import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

import numpy as np

a = 10. ** np.arange(100)

fig, ax = plt.subplots(1)
norm = mpl.colors.LogNorm(np.min(a), np.max(a))

img1 = ax.imshow(a[None,   :  ], extent = (0,  100,   0, 10),
                                 cmap = 'gray', norm = norm  )
img2 = ax.imshow(a[None,   :50], extent = (0,   50, -10,  0),
                                 cmap = 'gray', norm = norm  )
img3 = ax.imshow(a[None, 50:  ], extent = (50, 100, -10,  0),
                                 cmap = 'gray', norm = norm  )

plt.xlim(  0, 100)
plt.ylim(-10,  10)

divider = make_axes_locatable(plt.gca())
cax = divider.append_axes("bottom",
                          size=0.2,
                          pad=0.4 )
plt.colorbar(img1, cax = cax, orientation='horizontal')

plt.tight_layout()

plt.show()

Actual outcome

As we can see, left parts of each patch produced by .imshow() is completely black. It seems like rounding occurred somewhere. It also can be seen, that different colors are used to represent the same numbers in different arrays.

Figure_1

Expected outcome

It was expected to see smooth transition from black to white from left to right. It was also expected not to see any difference in colors representing same numbers.

Matplotlib version

  • Operating system: Linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.3.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.3

The matplotlib package was installed with pip.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions