Closed
Description
This is on 2.x (both the beta and current git HEAD) and confused me for the longest time:
from matplotlib import style
import matplotlib.pyplot as plt
def make_fig():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot([1, 2, 3], linestyle='dashed')
ax.grid(True)
return fig
with style.context('classic'):
fig = make_fig()
fig.savefig('test1.png')
fig.savefig('test2.png')
fig = make_fig()
fig.savefig('test3.png')
So the first save_fig()
gives the classic style as expected:
And the last save_fig()
gives the new defaults:
But for some reason the 2nd savefig()
, where the figure is created with the classic style, but is written outside the context manager gives a figure that looks like classic, except the dash pattern different:
This seriously confused me for the afternoon--it wreaks havoc with my tests where I'm now setting the stylesheet to classic inside the test. When pytest-mpl saves the test outside the context manager (and outside my test function) I get some weird abomination.