Skip to content

Instantly share code, notes, and snippets.

@grey-area
Created March 19, 2019 11:58
Show Gist options
  • Save grey-area/c215668d0fdf993b16c224faf779b90e to your computer and use it in GitHub Desktop.
Save grey-area/c215668d0fdf993b16c224faf779b90e to your computer and use it in GitHub Desktop.
Using matplotlib2tikz to generate tikz figures, and using them in latex
\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}
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