New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matplotlib 1.5 broken_barh fails on empty data. #5572
Comments
Can you provide a self-contained standalone example to reproduce this so I can git bisect to try to find the culprit? It's cool to hear that music21 is using matplotlib -- I wasn't aware of that. music21 looks like a really cool project (I used to dabble in computational musicology, but haven't been plugged into the field since the early 2000's). |
Here's a minimal program that demonstrates the problem: from matplotlib import pyplot
subplot = pyplot.subplot(1, 1, 1)
xrangesList = [[(0.2, 0.4), (0.6, 0.8)], []]
yrange = (.1, .5)
for xranges in xrangesList:
subplot.broken_barh(xranges, yrange) It's the second, empty list that causes the problem. Empty lists in xrangesList arise in our program because we were generating a bar graph for every data element but some of them didn't have a range associated with it. That could definitely be something on the "user-error" side for us to fix; it's only because it worked before that I mention it. The docs could instead be changed from "a sequence of" to "a non-empty sequence of" in various places. Since In axes/_axes.py self._process_unit_info(xdata=xranges[0],
ydata=yrange[0],
kwargs=kwargs) use: if len(xranges) > 0:
xdata = xranges[0]
else:
xdata = None
if len(yrange) > 0:
ydata = yrange[0]
else:
ydata = None
self._process_unit_info(xdata=xdata,
ydata=ydata,
kwargs=kwargs) Thanks for the kind words about computational musicology! Yes, we've been using matplotlib since 2007 for all our graphing needs. We don't use it as well as we could because we were still learning Python and numpy when we added graphing capabilities to the system and it's worked well enough that we haven't done a refactor. We absolutely love that we can use high code points in our axes, which makes this the only system that lets us use real sharp and flat signs in our axes. And everything else matplotlib enables. |
Fix #5572: Allow passing empty range to broken_barh
Fix #5572: Allow passing empty range to broken_barh
A change from 1.4 to 1.5 has caused subplots to not be able to plot broken bars where the xrange has no data. Previously an empty list as xranges worked fine (no data was added to the subplot). Now it throws an IndexError exception:
This could be considered a backwards-incompatible issue. Or maybe a feature. In any case, it was something that my toolkit (music21) was counting on being able to use in some cases; a simple "if len(xranges) > 0:" wrap around the call fixed it.
The text was updated successfully, but these errors were encountered: