Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
DataFrame.hist() does not get along with matplotlib.pyplot.tight_layout() #9351
Comments
ericmjl
commented
May 19, 2015
|
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. |
goyodiaz
referenced
this issue
in NSLS-II/dataportal
Dec 15, 2015
Closed
Mpl/Pandas plotting bug! #32
miraculixx
commented
Feb 25, 2016
|
+1 |
jreback
added Visualization Bug Difficulty Novice Effort Low
labels
Feb 26, 2016
jreback
added this to the
Next Major Release
milestone
Feb 26, 2016
jluttine
referenced
this issue
Jun 8, 2016
Closed
tight_layout not working with DataFrame.hist #13396
|
As of |
|
@ResidentMario can you add a test to confirm this behavior (that skips if mpl < 2.0)? |
ResidentMario
added a commit
to ResidentMario/pandas
that referenced
this issue
Feb 27, 2017
|
|
ResidentMario |
aced0ed
|
ResidentMario
added a commit
to ResidentMario/pandas
that referenced
this issue
Feb 27, 2017
|
|
ResidentMario |
5909635
|
ResidentMario
referenced
this issue
Feb 27, 2017
Merged
TST: DataFrame.hist() does not get along with matplotlib.pyplot.tight_layout() #15515
jreback
modified the milestone: 0.20.0, Next Major Release
Feb 27, 2017
jreback
closed this
in #15515
Feb 27, 2017
jreback
added a commit
that referenced
this issue
Feb 27, 2017
|
|
ResidentMario + jreback |
fed1827
|
naught101
commented
Mar 7, 2017
|
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:
|
|
|
|
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 |
jreback
reopened this
Mar 7, 2017
|
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() |
This was referenced Mar 7, 2017
|
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? |
ResidentMario
added a commit
to ResidentMario/pandas
that referenced
this issue
Mar 13, 2017
|
|
ResidentMario |
3583da9
|
|
@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. |
jorisvandenbossche
closed this
in #15671
Mar 13, 2017
jorisvandenbossche
added a commit
that referenced
this issue
Mar 13, 2017
|
|
ResidentMario + jorisvandenbossche |
998c801
|
AnkurDedania
added a commit
to AnkurDedania/pandas
that referenced
this issue
Mar 21, 2017
|
|
ResidentMario + AnkurDedania |
a38a957
|
AnkurDedania
added a commit
to AnkurDedania/pandas
that referenced
this issue
Mar 21, 2017
|
|
ResidentMario + AnkurDedania |
b8420ba
|
mattip
added a commit
to mattip/pandas
that referenced
this issue
Apr 3, 2017
|
|
ResidentMario + mattip |
39171b5
|
vfilimonov commentedJan 24, 2015
When
tight_layout()is called afterDataFrame.hist()it raisesAttributeError: 'NoneType' object has no attribute 'is_bboxif 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