Ask Your Question
0

How do I use a sage graph in LaTEX?

asked 2015-02-23 04:42:20 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I created a project in Sage that graphed multiple curves at once. Is there a way I can just import this graph or the code into LaTEX?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-02-24 02:07:30 +0200

dazedANDconfused gravatar image

Suppose you plot the sine function in Sage:

plot(sin(x), (x, 0, 2*pi))

and you want to save the picture. First, call the plot something:

plt  = plot(sin(x), (x, 0, 2*pi))

And now save it as a pdf:

plt.save("MyPic.pdf")

The tex engine you use will determine how you save your picture. Many people use pdflatex as the engine, in which case the pdf format is fine. If you are using a regular latex engine then eps, rather than pdf, is expected. The different options, and the process of including the picture using the graphicx package are covered in the LaTeX Wikibooks here. The sagetex package provides another way of getting your image in without saving. It lets you run Sage code when you use LaTeX--see the documentation on how to use it. But you need both LaTeX and Sage on your computer. Unless you're using Sagemath Cloud, getting Sage and LaTeX set up to communicate on your PC can be a hassle.

edit flag offensive delete link more

Comments

Thank you for the answer. I use texmaker as my complier. So I use plt.save("MyPic.pdf") and then how do I put it into texmaker?

ecain17 gravatar imageecain17 ( 2015-02-24 05:41:40 +0200 )edit

You'd create the picture using Sage. After running Sage, it would create the MyPic.pdf file. Place that in the file where your LaTeX document is. Make sure you've included the graphicx package in your latex preamble and then \includegraphics{MyPic.pdf} as explained in detail here.

dazedANDconfused gravatar imagedazedANDconfused ( 2015-02-24 06:42:01 +0200 )edit

Thank you I got it to work!

ecain17 gravatar imageecain17 ( 2015-02-24 07:46:29 +0200 )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: 2015-02-23 04:42:20 +0200

Seen: 1,780 times

Last updated: Feb 24 '15