Closed
Description
I stumbled across this regression trying to use the matplotlib 2.0 release candidate with yt.
In yt we have a plotting class called SlicePlot that will switch to a symlog colorbar if a user tries to plot a field that we want to be log-scaled because it has a lot of dynamic range but that also has negative values. A very simple yt script (that works fine under matplotlib 1.5.3 but dies with a traceback under 2.0.0rc1) that triggers this looks like:
import yt
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
p = yt.SlicePlot(ds, 2, 'x-velocity')
p.save()
To make this easier for people who aren't familiar with yt internals to digest, I've come up with the following test script that only uses matplotlib but triggers what I think is the same error:
import matplotlib
import numpy as np
from matplotlib import pyplot as plt
image = np.array(
[[-1, -1, -1],
[0, 0, 0],
[1, 1, 1]]
)
fig, ax = plt.subplots()
cax = fig.add_axes([0.85, 0.1, 0.1, 0.8])
norm = matplotlib.colors.SymLogNorm(0.1, vmin=-1, vmax=1)
image = ax.imshow(image, norm=norm, vmin=-1, vmax=1)
fig.colorbar(image, cax, format=matplotlib.ticker.LogFormatterMathtext())
plt.savefig('img.png')
It produces the following traceback:
Traceback (most recent call last):
File "test2.py", line 20, in <module>
fig.colorbar(image, cax, format=matplotlib.ticker.LogFormatterMathtext())
File "/usr/local/lib/python3.5/site-packages/matplotlib/figure.py", line 1601, in colorbar
cb = cbar.colorbar_factory(cax, mappable, **kw)
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 1347, in colorbar_factory
cb = Colorbar(cax, mappable, **kwargs)
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 926, in __init__
ColorbarBase.__init__(self, ax, **kw)
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 326, in __init__
self.draw_all()
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 351, in draw_all
self._config_axes(X, Y)
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 447, in _config_axes
self.update_ticks()
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 376, in update_ticks
ticks, ticklabels, offset_string = self._ticker()
File "/usr/local/lib/python3.5/site-packages/matplotlib/colorbar.py", line 615, in _ticker
formatter.set_locs(b)
File "/usr/local/lib/python3.5/site-packages/matplotlib/ticker.py", line 920, in set_locs
vmin = math.log(vmin) / math.log(b)
ValueError: math domain error
Under matplotlib 1.5.3 the same script produces the following image: