Opened 10 years ago
Last modified 6 years ago
#13232 new enhancement
LaTeX export for plots
Reported by: | nthiery | Owned by: | jason, was |
---|---|---|---|
Priority: | major | Milestone: | sage-7.3 |
Component: | graphics | Keywords: | latex, plot |
Cc: | ddrake, jhpalmieri, kcrisman, bertheville.chloe@…, thomas.ayoub@…, arthur.mauvezin@…, tscrim | Merged in: | |
Authors: | Thomas Ayoub, Bertheville Chloé, Arthur Mauvezin | Reviewers: | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Implement latex methods for plots to produce latex/tikz pictures.
Attachments (4)
Change History (20)
Changed 10 years ago by
comment:1 Changed 10 years ago by
- Cc ddrake added
comment:2 Changed 10 years ago by
- Cc jhpalmieri added
comment:3 Changed 10 years ago by
- Cc kcrisman added
Oh wow, this would be cool. Now I don't know which would look better - SageTeX with sageplot
environment or this?
comment:4 Changed 10 years ago by
comment:5 Changed 10 years ago by
- Cc bertheville.chloe@… thomas.ayoub@… arthur.mauvezin@… added
comment:6 Changed 10 years ago by
As an example, I attached the result of using this patch on the following plot::
sage: L = RootSystem(['A',2,1]).weight_space() sage: P = L.plot(size=[[-1..1],[-1..1]],alcovewalks=[[0,2,0,1,2,1,2,0,2,1]]); P
I had to tweak a tiny bit the latex, for tikz crashes with an arithmetic error when given the option color={rgb: red,0;green,0;blue,0
}. Otherwise, I guess that using
sage: view(P)
would have worked.
Anyway, it would be best to use named colors instead, and not to repeat opacity=1 all the time.
comment:7 follow-up: ↓ 8 Changed 10 years ago by
Some minor comments:
- Is it necessary or useful to add
_latex
method toGraphicsPrimitive
and override that from thearc
,line
, etc? I think this method is used only inGraphics
so that only one\begin{tikzpicture}
is used, right? Since the classesArc
,Line
, etc are not exposed hence it doesn't seem to matter whether the method is namedlatex
or_latex
. I am not sure which is the correct approach here, so I am just curious. - Should it return an empty string from
Graphics
if there are no objects in it? Again, I am just wondering because I am not sure which behavior is more appropriate. Currently, this patch results in the following behavior:sage: G = Graphics() sage: latex(G) \begin{tikzpicture} \end{tikzpicture} sage: len(G) 0
- The check for
None
should be done by usingis
oris not
, according to this PEP.
comment:8 in reply to: ↑ 7 Changed 10 years ago by
Replying to ppurka:
Some minor comments:
- Is it necessary or useful to add
_latex
method toGraphicsPrimitive
and override that from thearc
,line
, etc? I think this method is used only inGraphics
so that only one\begin{tikzpicture}
is used, right? Since the classesArc
,Line
, etc are not exposed hence it doesn't seem to matter whether the method is namedlatex
or_latex
. I am not sure which is the correct approach here, so I am just curious.
In any cases, all the methods should be named _latex_, for consistency with SageObject?. At this point, I don't see a use for having _latex_ in GraphicsPrimitive?, since there is already a default (admittedly pretty useless in this case) implementation in SageObject?.
- Should it return an empty string from
Graphics
if there are no objects in it? Again, I am just wondering because I am not sure which behavior is more appropriate. Currently, this patch results in the following behavior:sage: G = Graphics() sage: latex(G) \begin{tikzpicture} \end{tikzpicture} sage: len(G) 0
That's sounds reasonable; let's not introduce a special case.
- The check for
None
should be done by usingis
oris not
, according to this PEP.
+1
Thanks for your comments!
comment:9 Changed 10 years ago by
Chloe, Thomas, Arthur,
Are you planning to work further on this patch?
If not, any volunteer to take on this project?
comment:10 Changed 10 years ago by
A plot of a function produces unexciting results:
sage: p = plot(sin(x), (0, 2*pi)) sage: latex(p) \begin{tikzpicture} \draw [color={rgb: red,0;green,0;blue,1}, line width=1pt, opacity=1] (0.0,0.0) -- (0.0199042066897,0.0199028924494); \end{tikzpicture}
But perhaps we should focus on getting plots to work later.
comment:11 Changed 10 years ago by
Also, here are a couple links to projects for turning matplotlib things into TikZ:
https://github.com/nschloe/matplotlib2tikz
https://github.com/pwuertz/matplotlib-backend-pgf/
We might still want to do our own TikZ export, but those are potentially of use.
comment:12 Changed 9 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:13 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:14 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:15 Changed 8 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:16 Changed 6 years ago by
- Cc tscrim added
- Milestone changed from sage-6.4 to sage-7.3
In some ways, this is already handled by matplotlib's PGF export, but I think it would still be good to have a native (and more compact) version of the graphics objects (in particular, so it doesn't go through show
, need to create a temp file, and come with all of the "standard" plot things).
First draft written by three students of mine. More details to come after dinner :-)