If I use the Agg
backend, I'm unable to keep image windows open with show()
(regardless of block=True
or not)---they just close virtually immediately. If I don't use Agg
, then I get the warning:
/Library/Python/2.7/site-packages/matplotlib-1.2.0-py2.7-macosx-10.8-intel.egg/matplotlib/tight_layout.py:225: UserWarning: tight_layout : falling back to Agg renderer warnings.warn("tight_layout : falling back to Agg renderer")
Sample code:
import matplotlib as mpl
mpl.use('Agg') # With this line = figure disappears; without this line = warning
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
mu, sigma = 0, 0.5
x = np.linspace(-3, 3, 100)
plt.plot(x, mlab.normpdf(x, mu, sigma))
fig.tight_layout()
plt.show()
Is there a different backend or methodology I should be using?
The last, Agg, is a non-interactive backend that can only write to files. It is used on Linux, if Matplotlib cannot connect to either an X display or a Wayland display.
And with no additional code and only using the simple matplotlib code, the output is an interactive plot where you can zoom in/out, pan it and reset to the original view.
tight_layout automatically adjusts subplot params so that the subplot(s) fits in to the figure area. This is an experimental feature and may not work for some cases. It only checks the extents of ticklabels, axis labels, and titles.
The workaround, given by @FilipeCorreia in a comment, is to remove mpl.use('Agg')
, and use fig.set_tight_layout(True)
instead of fig.tight_layout()
.
Agg
is a non-interactive backend, meaning it won't display on the screen, only save to files. Which backend are you using? You have OSX, perhaps you can try the 'macosx', or an interactive backend that uses Agg (eg. QT4Agg, WXAgg).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With