Skip to content
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

BrokenBarHCollection not working with log scale axis #4276

Closed
hmigneron opened this issue Mar 25, 2015 · 3 comments
Closed

BrokenBarHCollection not working with log scale axis #4276

hmigneron opened this issue Mar 25, 2015 · 3 comments

Comments

@hmigneron
Copy link

This is part of a more complex situation in my code but here is a simplified version of what i'm doing :

import matplotlib

matplotlib.use("Agg")

from pylab import *
import matplotlib.font_manager
import matplotlib.gridspec as gridspec
import matplotlib.ticker
import numpy as np
import matplotlib.collections as collections


figure = figure(facecolor='white', figsize=(900/72, 350/72),dpi=72,frameon='true')
gs = gridspec.GridSpec(2, 1,height_ratios=[25,1],hspace=0.08)
ax = subplot(gs[0])

ax.xaxis.grid(True,'minor', color='#AAAAAA')
ax.yaxis.grid(True,'minor', color='#AAAAAA')
ax.xaxis.grid(True,'major', linewidth=1.1)
ax.yaxis.grid(True,'major', linewidth=1.1)

x = np.array([1,2,3,4,5])
y = np.array([1,4,9,16,25])
ax.plot(x,y)

xlim(xmin=1,xmax=5)
ylim(ymin=0.01,ymax=50)

ax.set_yscale('log')
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: str(round(x,1))))

collection = collections.BrokenBarHCollection.span_where(
        x, ymin=0, ymax=50, where=y>4, facecolor='red', alpha=0.125,linewidth=0)
ax.add_collection(collection)

savefig('test.png',dpi=72)

With that code the BrokenBarHCollection never gets displayed. However if I remove the ax.set_yscale('log') instructions things work perfect and the BrokenBarHCollection is displayed as expected.

I can reproduce this every time. Running python 2.7.3 on debian x64 7.8

@tacaswell
Copy link
Member

One of your bar edges is at 0 which (correctly) results in a -np.inf as the bottom edge of your bars. There are someplaces in the code which have 'clip' logic, but apparently not here (and in general, clipping is not the correct behavior as if 0 really is important, clipping it to what ever the bottom of your log-scale is is wrong).

As a work around, just set ymin to be non-zero.

@hmigneron
Copy link
Author

Wow, my bad, sorry about reporting this as a bug.

Thanks a lot for explaining the logic behind the non-clipping.

@hmigneron
Copy link
Author

Also, just FYI, I couldn't reproduce this when working on Windows (which is what lead me to believe it was a bug in the first place -- it works perfectly on Windows with ymin=0 so I guess it must clip).

I'm guessing the behavior was changed between whatever version the python-matplotlib package uses on debian vs the current 1.4.3 version. In any case, thanks again for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants