Elffuss BraidHub

kikocis/auto-code-rover public

main · 3.7 KiBRawPermalink
1[Bug]: Setting norm with existing colorbar fails with 3.6.3
2### Bug summary
3
4Setting the norm to a `LogNorm` after the colorbar has been created (e.g. in interactive code) fails with an `Invalid vmin` value in matplotlib 3.6.3.
5
6The same code worked in previous matplotlib versions.
7
8Not that vmin and vmax are explicitly set to values valid for `LogNorm` and no negative values (or values == 0) exist in the input data.
9
10### Code for reproduction
11
12```python
13import matplotlib.pyplot as plt
14from matplotlib.colors import LogNorm
15import numpy as np
16
17# create some random data to fill a 2d plot
18rng = np.random.default_rng(0)
19img = rng.uniform(1, 5, (25, 25))
20
21# plot it
22fig, ax = plt.subplots(layout="constrained")
23plot = ax.pcolormesh(img)
24cbar = fig.colorbar(plot, ax=ax)
25
26vmin = 1
27vmax = 5
28
29plt.ion()
30fig.show()
31plt.pause(0.5)
32
33plot.norm = LogNorm(vmin, vmax)
34plot.autoscale()
35plt.pause(0.5)
36```
37
38
39### Actual outcome
40
41```
42Traceback (most recent call last):
43 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 454, in _draw_idle
44 self.draw()
45 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py", line 405, in draw
46 self.figure.draw(self.renderer)
47 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/artist.py", line 74, in draw_wrapper
48 result = draw(artist, renderer, *args, **kwargs)
49 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
50 return draw(artist, renderer)
51 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/figure.py", line 3082, in draw
52 mimage._draw_list_compositing_images(
53 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
54 a.draw(renderer)
55 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
56 return draw(artist, renderer)
57 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 3100, in draw
58 mimage._draw_list_compositing_images(
59 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
60 a.draw(renderer)
61 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
62 return draw(artist, renderer)
63 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/collections.py", line 2148, in draw
64 self.update_scalarmappable()
65 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/collections.py", line 891, in update_scalarmappable
66 self._mapped_colors = self.to_rgba(self._A, self._alpha)
67 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/cm.py", line 511, in to_rgba
68 x = self.norm(x)
69 File "/home/mnoethe/.local/conda/envs/cta-dev/lib/python3.9/site-packages/matplotlib/colors.py", line 1694, in __call__
70 raise ValueError("Invalid vmin or vmax")
71ValueError: Invalid vmin or vmax
72```
73
74### Expected outcome
75
76Works, colorbar and mappable are updated with new norm.
77
78### Additional information
79
80_No response_
81
82### Operating system
83
84Linux
85
86### Matplotlib Version
87
883.6.3 (works with 3.6.2)
89
90### Matplotlib Backend
91
92Multpiple backends tested, same error in all (Qt5Agg, TkAgg, agg, ...)
93
94### Python version
95
963.9.15
97
98### Jupyter version
99
100not in jupyter
101
102### Installation
103
104conda