Why is plt.savefig() not working in texstudio?

28 Views Asked by At

I am trying to make a simple graph to show in my latex document using pythontex and it seems that plt.savefig() is not working. Here is the code i used for testing:

% !TeX TXS-program:compile = txs:///pythontex
\documentclass[a4paper, 12pt]{article}
\usepackage{pythontex}
\usepackage{mathtools, amsthm, amssymb, icomma, upgreek, xfrac}
\usepackage[utf8]{inputenc}
\usepackage{lmodern, microtype}
\usepackage{pgfplots}
\usepackage{graphicx}

\begin{document}
\begin{pycode}
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
x = np.linspace(-10, 10, 20)
f = 2*x
plt.plot(x, f)
plt.savefig('C:\\test\\1.png')
\end{pycode}
\end{document}

I tried to save image in specific locaiton like 'C:\test\1.png' and it didn't work. Tried to update matplotlib, it didn't work either. I simply want the png file to save in folder with the .tex file, so i can use it later in the document.

0

There are 0 best solutions below