Displaying a matplotlib picture using SageTeX
I couldn't draw the picture I want in a LaTeX document using SageTeX.
Here is my code.
I couldn't draw the picture I want in a LaTeX document using SageTeX.
Here is my code.
In the code you provide, the figure is saved in svg format.
Instead, you might want to save it to png format and then include it in your latex document.
The following works for me.
\documentclass[a4paper]{article}
\usepackage{sagetex}
\usepackage{graphicx}
\begin{document}%
\pagestyle{empty}
\begin{sagesilent}
import numpy as np
from scipy.fftpack import fft, ifft
N1 = 16
n1 = np.linspace(0.0, 16, N1)
y = np.array([np.cos(((2.0 * np.pi * i))/N1) for i in range (0, N1)])
yf = fft(y)
from matplotlib import pyplot as plt
fig = plt.figure(2)
fig.add_subplot(221)
plt.plot(n1, y)
fig.add_subplot(222)
plt.plot(n1, yf)
plt.savefig("test.png", format="png")
plt.close(fig)
\end{sagesilent}
\includegraphics[scale=0.6]{test.png}
\end{document}
The SageTeX manual and the SageTeX example file show how to use the \sageplot
command
to include Sage plots in a TeX document.
Here, you are using matplotlib, and saving a picture, so you need to save it in a format that can be included in a LaTeX document, and to actually include it.
Thank you slelievre. I too get out of the issue...
If this answers the question, please feel free to click the check mark so that others will know it has been answered!
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 8 years ago
Seen: 490 times
Last updated: Dec 09 '16
Is there any way to integrate matplotlib plots in my latex document using sagetex?
How to set matplotlib backend from SageTeX?
Can I convert a GraphicsArray object to a Graphics object?
Matplotlib navigation constrained pan or keybindings
Plotting arrows at the edges of a curve