ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 20 Sep 2014 11:05:45 +0200Convert plot in latexhttps://ask.sagemath.org/question/24193/convert-plot-in-latex/ Hi,
I would like to convert this sage code
point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])
in a latex environment, that are points of a linear congruential sequence for a 2-dimensional spectral test. I also would like to convert a 3-dimensional plot, a fixed extract of a cube, like the plot of RANDU from wikipedia (http://en.wikipedia.org/wiki/RANDU).
Can you help me? Thank you very much.Thu, 18 Sep 2014 18:41:54 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/Answer by kcrisman for <p>Hi,</p>
<p>I would like to convert this sage code </p>
<p>point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])</p>
<p>in a latex environment, that are points of a linear congruential sequence for a 2-dimensional spectral test. I also would like to convert a 3-dimensional plot, a fixed extract of a cube, like the plot of RANDU from wikipedia (<a href="http://en.wikipedia.org/wiki/RANDU">http://en.wikipedia.org/wiki/RANDU</a>).</p>
<p>Can you help me? Thank you very much.</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24194#post-id-24194You may find [SageTeX](http://www.sagemath.org/doc/tutorial/sagetex.html) useful!Thu, 18 Sep 2014 19:12:03 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24194#post-id-24194Answer by tmonteil for <p>Hi,</p>
<p>I would like to convert this sage code </p>
<p>point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])</p>
<p>in a latex environment, that are points of a linear congruential sequence for a 2-dimensional spectral test. I also would like to convert a 3-dimensional plot, a fixed extract of a cube, like the plot of RANDU from wikipedia (<a href="http://en.wikipedia.org/wiki/RANDU">http://en.wikipedia.org/wiki/RANDU</a>).</p>
<p>Can you help me? Thank you very much.</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24205#post-id-24205I see at least two possibilities:
If you want to include the image of the plot in a LaTeX document, save the image of the plot you see from your browser (right click + "Save Image As"), and call it, say ``my_plot.png``, within the directory where your ``.tex`` files lives. Then, in your LaTeX document, add something like:
\begin{figure}
\begin{center}
\includegraphics[width = 0.9 \linewidth]{my_plot.png}
\caption{My title} \label{my_label}
\end{center}
\end{figure}
If you want LaTeX to reproduce your picture, you can let Sage generate a piece of ``tikz``:
sage: L = [(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)]
sage: for (x,y) in L:
print(r" \draw ({0},{1}) node {{$\bullet$}} ;".format(x,y))
....:
\draw (0,0) node {$\bullet$} ;
\draw (1,5) node {$\bullet$} ;
\draw (5,2) node {$\bullet$} ;
\draw (2,10) node {$\bullet$} ;
\draw (10,4) node {$\bullet$} ;
\draw (4,20) node {$\bullet$} ;
\draw (20,8) node {$\bullet$} ;
\draw (8,17) node {$\bullet$} ;
\draw (17,16) node {$\bullet$} ;
\draw (16,11) node {$\bullet$} ;
\draw (11,9) node {$\bullet$} ;
\draw (9,22) node {$\bullet$} ;
\draw (22,18) node {$\bullet$} ;
\draw (18,21) node {$\bullet$} ;
\draw (21,13) node {$\bullet$} ;
\draw (13,19) node {$\bullet$} ;
\draw (19,3) node {$\bullet$} ;
\draw (3,15) node {$\bullet$} ;
\draw (15,6) node {$\bullet$} ;
\draw (6,7) node {$\bullet$} ;
\draw (7,12) node {$\bullet$} ;
\draw (12,14) node {$\bullet$} ;
\draw (14,1) node {$\bullet$} ;
and then include it in a LaTeX document:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.5]
<---- copy/paste the previous output here
\end{tikzpicture}
\end{document}
Fri, 19 Sep 2014 13:50:57 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24205#post-id-24205Comment by torti for <p>I see at least two possibilities:</p>
<p>If you want to include the image of the plot in a LaTeX document, save the image of the plot you see from your browser (right click + "Save Image As"), and call it, say <code>my_plot.png</code>, within the directory where your <code>.tex</code> files lives. Then, in your LaTeX document, add something like:</p>
<pre><code>\begin{figure}
\begin{center}
\includegraphics[width = 0.9 \linewidth]{my_plot.png}
\caption{My title} \label{my_label}
\end{center}
\end{figure}
</code></pre>
<p>If you want LaTeX to reproduce your picture, you can let Sage generate a piece of <code>tikz</code>:</p>
<pre><code>sage: L = [(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)]
sage: for (x,y) in L:
print(r" \draw ({0},{1}) node {{$\bullet$}} ;".format(x,y))
....:
\draw (0,0) node {$\bullet$} ;
\draw (1,5) node {$\bullet$} ;
\draw (5,2) node {$\bullet$} ;
\draw (2,10) node {$\bullet$} ;
\draw (10,4) node {$\bullet$} ;
\draw (4,20) node {$\bullet$} ;
\draw (20,8) node {$\bullet$} ;
\draw (8,17) node {$\bullet$} ;
\draw (17,16) node {$\bullet$} ;
\draw (16,11) node {$\bullet$} ;
\draw (11,9) node {$\bullet$} ;
\draw (9,22) node {$\bullet$} ;
\draw (22,18) node {$\bullet$} ;
\draw (18,21) node {$\bullet$} ;
\draw (21,13) node {$\bullet$} ;
\draw (13,19) node {$\bullet$} ;
\draw (19,3) node {$\bullet$} ;
\draw (3,15) node {$\bullet$} ;
\draw (15,6) node {$\bullet$} ;
\draw (6,7) node {$\bullet$} ;
\draw (7,12) node {$\bullet$} ;
\draw (12,14) node {$\bullet$} ;
\draw (14,1) node {$\bullet$} ;
</code></pre>
<p>and then include it in a LaTeX document:</p>
<pre><code>\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.5]
<---- copy/paste the previous output here
\end{tikzpicture}
\end{document}
</code></pre>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24217#post-id-24217@tmonteil thank you, it worked very well. have a nice day!Sat, 20 Sep 2014 11:05:45 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24217#post-id-24217Answer by torti for <p>Hi,</p>
<p>I would like to convert this sage code </p>
<p>point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])</p>
<p>in a latex environment, that are points of a linear congruential sequence for a 2-dimensional spectral test. I also would like to convert a 3-dimensional plot, a fixed extract of a cube, like the plot of RANDU from wikipedia (<a href="http://en.wikipedia.org/wiki/RANDU">http://en.wikipedia.org/wiki/RANDU</a>).</p>
<p>Can you help me? Thank you very much.</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24197#post-id-24197 I am working in the cloud, so i cant use sagetex, is there another possibility?Thu, 18 Sep 2014 19:51:28 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24197#post-id-24197Comment by dazedANDconfused for <p>I am working in the cloud, so i cant use sagetex, is there another possibility?</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24198#post-id-24198[SageMath Cloud](https://cloud.sagemath.com/) is in the cloud, is free, and gives you access to LaTeX, Sage, sagetex, and a lot more.Thu, 18 Sep 2014 22:58:39 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24198#post-id-24198Comment by dazedANDconfused for <p>I am working in the cloud, so i cant use sagetex, is there another possibility?</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24215#post-id-24215What doesn't work for you? SageMath Cloud? tmonteil's code? William Stein's code? If you follow the solution given by William Stein then your problem should be solved. If it doesn't work you should comment under his answer why it doesn't work. If you're not working in the cloud then Sage has to be installed on your computer.Fri, 19 Sep 2014 23:15:03 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24215#post-id-24215Comment by torti for <p>I am working in the cloud, so i cant use sagetex, is there another possibility?</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24202#post-id-24202It doesnt worked for me, can you please make an example with my plot
point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)]) ?
I want this diagram in my latex document. Thank you.Fri, 19 Sep 2014 08:23:00 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?comment=24202#post-id-24202Answer by William Stein for <p>Hi,</p>
<p>I would like to convert this sage code </p>
<p>point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])</p>
<p>in a latex environment, that are points of a linear congruential sequence for a 2-dimensional spectral test. I also would like to convert a 3-dimensional plot, a fixed extract of a cube, like the plot of RANDU from wikipedia (<a href="http://en.wikipedia.org/wiki/RANDU">http://en.wikipedia.org/wiki/RANDU</a>).</p>
<p>Can you help me? Thank you very much.</p>
https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24214#post-id-24214(Posting as an answer rather than comment, for the formatting.) Here's how in SageMathCloud, which fully supports SageTex.
1. Create a LaTeX document in SageMathCloud.
2. Replace the contents by the following, and click save. Wait a little for sage/latex to automatically run. Done.
\documentclass{article}
\title{Sagetex Plot Example}
\author{William Stein}
\usepackage{sagetex}
\begin{document}
\maketitle
\sageplot[width=.7\textwidth]{point([(0,0), (1,5), (5,2), (2,10), (10,4), (4,20), (20,8), (8,17), (17,16), (16,11), (11,9), (9,22), (22,18), (18,21), (21,13), (13,19), (19,3), (3,15), (15,6), (6,7), (7,12), (12,14), (14,1)])}
\end{document}
Fri, 19 Sep 2014 20:57:37 +0200https://ask.sagemath.org/question/24193/convert-plot-in-latex/?answer=24214#post-id-24214