-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DataFrame.hist() does not get along with matplotlib.pyplot.tight_layout() #9351
Comments
Ditto here, I can't seem to figure out what's going on. |
Would either of you want to dig into what's causing the problem? It seems that 129 tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots]) in |
Actually, just before the error is raised, Looks like a matplotlib issue to me, or maybe pandas should not be creating that invisible A quick workaround would be to add something like this:
But it might have side effects. |
+1 |
As of |
@ResidentMario can you add a test to confirm this behavior (that skips if mpl < 2.0)? |
This might be a different cause, but tight_layout is still not playing well with $ scripts/exploratory_analysis/site_analysis.py QC_histogram
/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/__init__.py:898: MatplotlibDeprecationWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
mplDeprecation)
Traceback (most recent call last):
File "scripts/exploratory_analysis/site_analysis.py", line 122, in <module>
main(args)
File "scripts/exploratory_analysis/site_analysis.py", line 112, in main
QC_plot(sites, variables, variant='histogram')
File "scripts/exploratory_analysis/site_analysis.py", line 94, in QC_plot
fig.tight_layout()
File "/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/figure.py", line 1943, in tight_layout
rect=rect)
File "/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/tight_layout.py", line 345, in get_tight_layout_figure
pad=pad, h_pad=h_pad, w_pad=w_pad)
File "/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/tight_layout.py", line 126, in auto_adjust_subplotpars
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots])
File "/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/transforms.py", line 723, in union
x0 = np.min([bbox.xmin for bbox in bboxes])
File "/home/naught101/miniconda3/envs/science/lib/python3.5/site-packages/matplotlib/transforms.py", line 723, in <listcomp>
x0 = np.min([bbox.xmin for bbox in bboxes])
AttributeError: 'NoneType' object has no attribute 'xmin' I figured this might have been fixed in newer versions, so I updated most things to git versions (which is more painful that I'd have liked, with conda...). Current versions are:
|
😞 I'll try looking for a fix, then, now that I've mucked this issue up. |
OK, so the non-working code is:
I consciously avoid working with plot methods directly, preferring to use the plot accessor methods instead (so
TIL these actually result in radically different output! To replicate this bug using the accessor method you have to further specifiy:
The test I added in the closing commit did use
Which passes, because it creates a |
So I haven't quite finished investigating this, but here's what I think so far: the core of Since it does this in a loop which iterates over the data, this means that in this example case it only does so three times, leaving the last layout element undefined. That axis then has a This may be reportable as a bug in |
ok reopening |
This boils down to a import matplotlib.pyplot as plt
f, axarr = plt.subplots(2, 2)
axarr[1][1].set_visible(False)
plt.tight_layout() Going about it a slightly different way, this works: import matplotlib.pyplot as plt
f, axarr = plt.subplots(2, 2)
axarr[1][1].axis('off')
plt.tight_layout() |
thanks @ResidentMario ok can update the release note at some point. any additional tests needed? |
@jreback I would say no, the PR included a regression test for this in the |
@ResidentMario the regression test passed though, contrary to the bug fix that was needed, right? (IIRC you did another PR which added a slightly different test which failed though..?) |
this was corrected in 03dca96 any reason not to close this issue? |
@jreback Wasn't sure what best practice is for telling users to use a version of a downstream library which may or may not be out yet (maybe |
Yeah, I saw the typo of 0.2 vs 2.0, and thought to directly make this 2.0.1, because that is more correct. |
…_layout() (pandas-dev#15515) * Add unit test for pandas-dev#9351 * Tweaks. * add _check_plot_works; rm aux method * Add whatsnew entry.
When
tight_layout()
is called afterDataFrame.hist()
it raisesAttributeError: 'NoneType' object has no attribute 'is_bbox
if any of subplots is empty (number of charts with histograms is smaller than number os subplots).I.e. the following code:
works fine, but this code:
raises
AttributeError
.My versions:
pandas: 0.15.2
numpy: 1.9.1
scipy: 0.14.1
IPython: 2.3.1
matplotlib: 1.4.2
The text was updated successfully, but these errors were encountered: