# 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.

edit retag close merge delete

Sort by » oldest newest most voted

(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}

more

You may find SageTeX useful!

more

I 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}

more

I am working in the cloud, so i cant use sagetex, is there another possibility?

more

1

[SageMath Cloud](https://cloud.sagemath.com/) is in the cloud, is free, and gives you access to LaTeX, Sage, sagetex, and a lot more.

It 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.

What 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.