#14798: Export graphics objects to PGF/TikZ
-------------------------------------+-------------------------------------
Reporter: etn40ff | Owner: jason, was
Type: enhancement | Status: needs_work
Priority: minor | Milestone: sage-7.1
Component: graphics | Resolution:
Keywords: matplotlib, plot, | Merged in:
TikZ, days49 | Reviewers: Frédéric Chapoton
Authors: Salvatore Stella | Work issues:
Report Upstream: Completely fixed; | Commit:
Fix reported upstream | 86f97279128d38ed9eb526623232e4fe165fad37
Branch: | Stopgaps:
public/ticket/14798 |
Dependencies: #19988 |
-------------------------------------+-------------------------------------
Comment (by etn40ff):
Dear All,
thank you for dealing with this while I had not sage to play with.
I am back at it now and I agree with the changes made so far.
One thing I am not convinced of is how the output of `view` looks like:
the
figure is all squashed to the right side.
A possible fix to this is to enclose the output of `latex()` into a
`\makebox[\textwidth]{` `}`. This unfortunately creates some problem with
latex
itself. Somehow if we put things inside a `\makebox` environment then
latex
complains about undefined control sequence `\pgfsys`. The latex code works
perfectly without the `\makebox`. To replicate this do as follows:
With the current code
{{{
sage: c = plot(sin(x))
sage: view(c)
}}}
works but the figure is all squashed to the right.
Apply this patch then and try again
{{{
diff --git a/src/sage/misc/latex.py b/src/sage/misc/latex.py
index de63252..ee62c3e 100644
--- a/src/sage/misc/latex.py
+++ b/src/sage/misc/latex.py
@@ -1768,7 +1768,9 @@ def _latex_file_(objects, title='SAGE', debug=False,
\
for i in range(len(objects)):
x = objects[i]
L = latex(x)
- if not '\\begin{verbatim}' in L:
+ if '\\begin{pgfpicture}' in L:
+ s += '\n\\makebox[\\textwidth]{\n%s\n}\n'%L
+ elif not '\\begin{verbatim}' in L:
s += '%s%s%s'%(math_left, L, math_right)
else:
s += '%s'%L
}}}
{{{
sage: c = plot(sin(x))
sage: view(c) #fails with undefined control sequence \pgfsys
sage: c._show_axes = False
sage: view(c) #works and places the figure nicely
}}}
Apparently the issue is with the axes.
To get the code that sages tries to compile you can do
{{{
sage: from sage.misc.latex import _latex_file_
sage: s = _latex_file_(latex(c))
sage: f = open('/tmp/sage.tex','w'); f.write(s); f.close()
}}}
Any idea on how to tackle this?
One more issue (this, I think, is a bug upstream):
{{{
sage: c = text('Hello World!',(1,0))
sage: latex(c)
...
IOError: [Errno 32] Broken pipe
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/14798#comment:39>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.