Closed
Description
Bug report
Bug summary
Creating a colorbar with a SymLogNorm
fails, using the fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax)
example given in the docs.
Code for reproduction
import matplotlib.pyplot as plt
import matplotlib.colors as mcolor
import matplotlib.cm as cm
norm = mcolor.SymLogNorm(5)
fig, ax = plt.subplots()
fig.colorbar(cm.ScalarMappable(norm=norm, cmap='viridis'), cax=ax)
Actual outcome
Traceback (most recent call last):
File "test.py", line 8, in <module>
fig.colorbar(cm.ScalarMappable(norm=norm, cmap='viridis'), cax=ax)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py", line 2201, in colorbar
cb = cbar.colorbar_factory(cax, mappable, **cb_kw)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colorbar.py", line 1686, in colorbar_factory
cb = Colorbar(cax, mappable, **kwargs)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colorbar.py", line 1210, in __init__
ColorbarBase.__init__(self, ax, **kwargs)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colorbar.py", line 472, in __init__
self.draw_all()
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colorbar.py", line 495, in draw_all
self._process_values()
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colorbar.py", line 945, in _process_values
b = self.norm.inverse(self._uniform_y(self.cmap.N + 1))
File "/Users/dstansby/github/matplotlib/lib/matplotlib/colors.py", line 1276, in inverse
val = val * (self._upper - self._lower) + self._lower
AttributeError: 'SymLogNorm' object has no attribute '_upper'
Expected outcome
No error
Matplotlib version
- Operating system: macOS 10.15.2
- Matplotlib version: '3.2.0rc2.post1221+g20805b805'
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.7
- Jupyter version (if applicable):
- Other libraries: