8000 imshow with LogNorm crashes with certain inputs · Issue #18415 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
imshow with LogNorm crashes with certain inputs #18415
Closed
@LevN0

Description

@LevN0

Bug report

Bug summary

Due to changes introduced in 3dea5c7, trying to display some images with LogNorm will crash because vmin gets auto-adjusted to 0 (which is invalid for LogNorm).

Code for reproduction

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

data = np.full((500, 500), -1, dtype=np.float64)
data[0:250, :] = 1E20

fig, ax = plt.subplots()
im = ax.imshow(data, norm=LogNorm(vmin=100, vmax=data.max()))

plt.show()

Actual outcome

  File "C:\Python38\lib\site-packages\matplotlib\image.py", line 922, in make_image
    return self._make_image(self._A, bbox, transformed_bbox, clip,
  File "C:\Python38\lib\site-packages\matplotlib\image.py", line 541, in _make_image
    output = self.norm(resampled_masked)
  File "C:\Python38\lib\site-packages\matplotlib\colors.py", line 1193, in __call__
    self._check_vmin_vmax()
  File "C:\Python38\lib\site-packages\matplotlib\colors.py", line 1182, in _check_vmin_vmax
    raise ValueError("minvalue must be positive")
ValueError: minvalue must be positive

Expected outcome

Showed a plot in MPL 3.1 (and I believe every version until 3.3). The crash is coming from _make_image transforming vmin to be zero per changes added in 3dea5c7. I guess perhaps the solution is "then don't try to plot that, use a vmin closer to your vmax" but kind of inconvenient for code that previously worked fine.

Matplotlib version: 3.3.1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0