Ask Your Question
1

Convert plot in latex

asked 2014-09-18 18:41:54 +0100

torti gravatar image

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 flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
2

answered 2014-09-19 20:57:37 +0100

William Stein gravatar image

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

edit flag offensive delete link more
1

answered 2014-09-18 19:12:03 +0100

kcrisman gravatar image

You may find SageTeX useful!

edit flag offensive delete link more
0

answered 2014-09-19 13:50:57 +0100

tmonteil gravatar image

updated 2014-09-19 13:56:32 +0100

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}
edit flag offensive delete link more

Comments

@tmonteil thank you, it worked very well. have a nice day!

torti gravatar imagetorti ( 2014-09-20 11:05:45 +0100 )edit
0

answered 2014-09-18 19:51:28 +0100

torti gravatar image

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

edit flag offensive delete link more

Comments

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.

dazedANDconfused gravatar imagedazedANDconfused ( 2014-09-18 22:58:39 +0100 )edit

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.

torti gravatar imagetorti ( 2014-09-19 08:23:00 +0100 )edit

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.

dazedANDconfused gravatar imagedazedANDconfused ( 2014-09-19 23:15:03 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-09-18 18:41:54 +0100

Seen: 733 times

Last updated: Sep 19 '14