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
{{ message }}
Repository navigation
CGContextRef is NULL of tight_layout with MacOSX backend #2654
This may be related to #166, but has a quite different immediate cause, so I'm reporting it separately. It might be that I should instead report this in ipython, so feel free to redirect me there, if that's more appropriate
If I do the following in ipython started with ipython -pylab=MacOSX :
I get a CGContextRef is NULL exception (full traceback in the first comment). The plot still appears, but it does not have the tight-layout applied. If I change the function instead to:
Currently, tight_layout makes the layout tight but does not maintain tightness. So if I call tight_layout but then add a label to an axis or resize the figure, the layout will not be tight anymore (it will be either too tight or not tight enough). Is this how it is supposed to function?
Currently, tight_layout makes the layout tight but does not maintain tightness. So if I call tight_layout but then add a label to an axis or resize the figure, the layout will not be tight anymore (it will be either too tight or not tight enough). Is this how it is supposed to function?
Btw the comment above is relevant for this bug. Depending on how tight_layout is supposed to function, the offending code may need to move to figure.draw. If so, it would be called from inside the event loop, and this bug would go away.
My understanding has been that this is meant to be a one-shot function, to
be used prior to show() and/or savefig(). A couple years ago, I did put up
a PR for adding a tight_layout() button that could be used in interactive
mode, but it didn't gather enough interest at that time. Of course,
tight_layout() was much less mature at that time, so maybe it is time to
revisit that decision?
If tight_layout is redesigned, I'd be happy to help out in making sure that this bug doesn't reappear. This shouldn't be too hard: As long as the renderer is only used from inside the event loop callback (i.e., somewhere within the call to figure.draw), everything should be OK. The current tight_layout code on the other hand uses the renderer outside of figure.draw, which is causing this bug.
Having the same problem here myself. Does anyone have any recommendations for alternative backends in OSX? PyQT is giving me some speed problems with ipython (ipython -pylab=qt) with:
@ribonoous - I've generally used Tk when having problems with the other backends - it seems to nearly always work at least ok.
Another option for the specific problem here is to do gcf().set_tight_layout(True) before plotting. For me that worked, even though the pylab.tight_layout call gave the error here.
a temporary solution
Do not include tight_layout in your script/code.
After plotting it, use tight_layout on terminal before/after showing it if you want. Then save it.
I just add plt.show() before tight_layout() as below. And it works for me.
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="dark")
rs = np.random.RandomState(50)
# Set up the matplotlib figure
f, axes = plt.subplots(3, 3, figsize=(9, 9), sharex=True, sharey=True)
# Rotate the starting point around the cubehelix hue circle
for ax, s in zip(axes.flat, np.linspace(0, 3, 10)):
# Create a cubehelix colormap to use with kdeplot
cmap = sns.cubehelix_palette(start=s, light=1, as_cmap=True)
# Generate and plot a random bivariate dataset
x, y = rs.randn(2, 50)
sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=ax)
ax.set(xlim=(-3, 3), ylim=(-3, 3))
plt.show() # I just add this line, and it works
f.tight_layout()
Activity
eteq commentedon Dec 5, 2013
Traceback:
mdboom commentedon Dec 5, 2013
Cc: @mdehoon
mdehoon commentedon Dec 9, 2013
Currently, tight_layout makes the layout tight but does not maintain tightness. So if I call tight_layout but then add a label to an axis or resize the figure, the layout will not be tight anymore (it will be either too tight or not tight enough). Is this how it is supposed to function?
mdehoon commentedon Dec 9, 2013
Currently, tight_layout makes the layout tight but does not maintain tightness. So if I call tight_layout but then add a label to an axis or resize the figure, the layout will not be tight anymore (it will be either too tight or not tight enough). Is this how it is supposed to function?
mdehoon commentedon Dec 9, 2013
Btw the comment above is relevant for this bug. Depending on how tight_layout is supposed to function, the offending code may need to move to figure.draw. If so, it would be called from inside the event loop, and this bug would go away.
WeatherGod commentedon Dec 9, 2013
My understanding has been that this is meant to be a one-shot function, to
be used prior to show() and/or savefig(). A couple years ago, I did put up
a PR for adding a tight_layout() button that could be used in interactive
mode, but it didn't gather enough interest at that time. Of course,
tight_layout() was much less mature at that time, so maybe it is time to
revisit that decision?
mdehoon commentedon Dec 10, 2013
If tight_layout is redesigned, I'd be happy to help out in making sure that this bug doesn't reappear. This shouldn't be too hard: As long as the renderer is only used from inside the event loop callback (i.e., somewhere within the call to figure.draw), everything should be OK. The current tight_layout code on the other hand uses the renderer outside of figure.draw, which is causing this bug.
amelio-vazquez-reina commentedon Feb 12, 2014
Having the same problem here myself. Does anyone have any recommendations for alternative backends in OSX? PyQT is giving me some speed problems with ipython (
ipython -pylab=qt) with:In case it matters, I am using conda.
Thanks,
Josh
eteq commentedon Feb 12, 2014
@ribonoous - I've generally used Tk when having problems with the other backends - it seems to nearly always work at least ok.
Another option for the specific problem here is to do
gcf().set_tight_layout(True)before plotting. For me that worked, even though thepylab.tight_layoutcall gave the error here.tacaswell commentedon Feb 25, 2014
Tagging this as 1.5.x as this seems to involve a major re-write. Please re-milestone if I am wrong.
Change tight_layout commands to avoid errors on Mac OSX
absimaHere commentedon Oct 27, 2014
a temporary solution
Do not include tight_layout in your script/code.
After plotting it, use tight_layout on terminal before/after showing it if you want. Then save it.
huangshiyu13 commentedon Mar 25, 2017
I just add plt.show() before tight_layout() as below. And it works for me.