You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ax.bar() fails if the input data has units. This is a fairly new bug as it worked fine at some point in the past. The exception is:
/home/trd/work/git/matplotlib/build/lib.linux-x86_64-3.6/matplotlib/axes/_base.py:2500: RuntimeWarning: invalid value encountered in double_scalars
delta = (x1t - x0t) * margin
The issue is that the unit conversion code is being run after a call to np.broadcast_arrays so that the x values are not actually arrays, they're still lists of units. The fix is re-order the code in bar() so that the unit conversion happens first.
Code for reproduction
I'll send in a pull request w/ a fix once I can get the right version of free type to install so I can run existing tests and create a baseline file. This occurs on the current master branch code.
New test case being added to test_units.py which will throw the exception:
@image_comparison(baseline_images=['jpl_bar_units'], extensions=['png'],
savefig_kwarg={'dpi': 60})
def test_jpl_bar_units():
from datetime import datetime
import matplotlib.testing.jpl_units as units
units.register()
day = units.Duration("ET", 24.0 * 60.0 * 60.0)
x = [units.Epoch("ET", dt=datetime(2009, 4, 25)),
units.Epoch("ET", dt=datetime(2009, 4, 26)),
units.Epoch("ET", dt=datetime(2009, 4, 27))]
width = [3*day, 2*day, 1*day]
fig, ax = plt.subplots()
ax.bar(x, width)
Activity
TD22057 commentedon Feb 27, 2018
FYI: @jrevans
jklymak commentedon Feb 27, 2018
Thanks for the potential PR: If you don't need the text for the test, you can call as:
Also, for new tests, we are trying to use
'mpl20'.tacaswell commentedon Feb 27, 2018
@TD22057 See https://matplotlib.org/devel/contributing.html?highlight=local_freetype#building-matplotlib-for-image-comparison-tests . I have
export MPLLOCALFREETYPE=1in my bashrc which will take care of downloading and building the correct version of freetype.Fixes matplotlib#10619. Reordered bar plot to correctly handle units