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
When defining an rcParams entry that is related to linestyle with an (on, off, ....) pattern, and using a style context manager somewhere in the code to temporarily apply other values of rcParams, an exception occurs.
Code for reproduction
Here is an example with the grid linestyle. (Related discussion on gitter.)
importmatplotlib.pyplotaspltfrommatplotlibimportrcParamsrcParams["grid.linestyle"] = (4, 4) # no error with something liked "dotted"fig=plt.figure()
withplt.style.context(["default"]):
ax0=fig.add_subplot(121)
ax0.grid()
ax1=fig.add_subplot(122)
ax1.grid()
#fig.savefig("test.png")
Actual outcome
An exception is raised. With Matplotlib 2.1.0 and the master branch:
ValueError: Key grid.linestyle: linestyle (None, [4.0, 4.0]) is not a valid on-off ink sequence.
See at the end of the post for the full traceback.
I think this is occurs when exiting the style context manager. It looks like the linestyle given as (on, off, ...) is internally processed and stored into a form (offset, (on, off, ...)) that is actually not recognized by the line validator, which then raises an error when it is passed back to rcParams to restore the former style.
Please note that it may not even be due to the stricter linestyle validation that was introduced in Matplotlib 2.1 (#8040), as Matplotlib 2.0.2 as well as Matplotlib 1.5.3 also throw an exception, although slightly different:
ValueError: You passed in an invalid linestyle, `(4, 4)`. See docs of Line2D.set_linestyle for valid values.
Expected outcome
No exception when exiting the style context manager, and a plot with 2 different grid linestyles, both defined through the dedicated "grid.linestyle" entry in rcParams.
Matplotlib version
Operating system: Linux (Fedora 26)
Matplotlib version: 2.1.0 from conda, master, 1.5.3 and 2.0.2 from the git repo
rcParams is sometimes treated as a singleton so replacing it with a new dictionary may have surprising side effects. We are using dict.update here to avoid re-validating things that we know are valid.
I suspect that the linestyle validator needs to learn to understand the (offset, [pattern]) input.
Bug summary
When defining an rcParams entry that is related to linestyle with an (on, off, ....) pattern, and using a style context manager somewhere in the code to temporarily apply other values of rcParams, an exception occurs.
Code for reproduction
Here is an example with the grid linestyle. (Related discussion on gitter.)
Actual outcome
An exception is raised. With Matplotlib 2.1.0 and the master branch:
See at the end of the post for the full traceback.
I think this is occurs when exiting the style context manager. It looks like the linestyle given as
(on, off, ...)
is internally processed and stored into a form(offset, (on, off, ...))
that is actually not recognized by the line validator, which then raises an error when it is passed back to rcParams to restore the former style.Please note that it may not even be due to the stricter linestyle validation that was introduced in Matplotlib 2.1 (#8040), as Matplotlib 2.0.2 as well as Matplotlib 1.5.3 also throw an exception, although slightly different:
Expected outcome
No exception when exiting the style context manager, and a plot with 2 different grid linestyles, both defined through the dedicated "grid.linestyle" entry in rcParams.
Matplotlib version
print(matplotlib.get_backend())
): Qt5AggMiscellaneous
The full traceback of the exception (with Matplotlib from the master branch):
The text was updated successfully, but these errors were encountered: