Created
March 19, 2019 11:58
-
-
Save grey-area/c215668d0fdf993b16c224faf779b90e to your computer and use it in GitHub Desktop.
Using matplotlib2tikz to generate tikz figures, and using them in latex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage[utf8]{inputenc} | |
\usepackage{tikz} | |
\usepackage{pgfplots} | |
\begin{document} | |
\begin{figure}[ht] | |
\centering | |
\resizebox{6cm}{!}{\input{test.tex}} | |
\caption{Testing} | |
\label{fig:1} | |
\end{figure} | |
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
N = 1000 | |
x = np.random.normal(scale=2, size=N) | |
y = 0.6*x + np.random.normal(scale=0.5, size=N) | |
plt.scatter(x, y, alpha=0.2, label='One') | |
x = np.random.normal(scale=2, size=N) | |
y = -0.2*x + np.random.normal(scale=0.5, size=N) | |
plt.scatter(x, y, alpha=0.2, label='Two') | |
plt.xlabel('x') | |
plt.ylabel('y') | |
plt.legend() | |
from matplotlib2tikz import save as tikz_save | |
tikz_save('test.tex') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment