Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Linestyle pattern depends on current style, not style set at creation #6592

Closed
@dopplershift

Description

@dopplershift

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:
test1
And the last save_fig() gives the new defaults:
test3
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:
test2
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions