sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.42k stars 476 forks source link

Fix using matplotlib stylesheets in plots #31870

Open haraldschilly opened 3 years ago

haraldschilly commented 3 years ago

The 2D plotting documentation suggests one can use matplotlib stylesheets, but provides no example.

This fails:

sage: plot(sin(x^2), (x, 0, 2*pi), stylesheet="bmh")
Traceback (most recent call last)
...
RuntimeError: Error in line(): option 'stylesheet' not valid.

Expected: this works and there is an example in the docs.

Workaround:

sage: import matplotlib.pyplot as plt
sage: plt.style.use('bmh')
sage: plot(sin(x^2), (x, 0, 2*pi))
Launched png viewer for Graphics object consisting of 1 graphics primitive

CC: @slel

Component: graphics

Keywords: plot, matplotlib, stylesheet

Issue created by migration from https://trac.sagemath.org/ticket/31870

slel commented 3 years ago

Changed keywords from none to plot, matplotlib, stylesheet

slel commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,11 +1,24 @@
-I'm not sure how to use the `stylesheet` option for plots. The documentation https://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html#sage.plot.plot.plot suggests this should work, but I don't see an example. When I try `plot(sin(x^2), (x, 0, 2*pi), stylesheet="bmh")` I get a stacktrace.
+The [2D plotting documentation](https://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html#sage.plot.plot.plot)
+suggests one can use matplotlib stylesheets,
+but provides no example.

-expected: this works and there is an example in the docs.
-
-workaround:
+This fails:

-import matplotlib.pyplot as plt -plt.style.use('bmh') -plot(sin(x^2), (x, 0, 2pi)) +sage: plot(sin(x^2), (x, 0, 2pi), stylesheet="bmh") +Traceback (most recent call last) +... +RuntimeError: Error in line(): option 'stylesheet' not valid.

+
+Expected: this works and there is an example in the docs.
+
+Workaround:
+
+```
+sage: import matplotlib.pyplot as plt
+sage: plt.style.use('bmh')
+sage: plot(sin(x^2), (x, 0, 2*pi))
+Launched png viewer for Graphics object consisting of 1 graphics primitive
+```
+