tikzplotlib
tikzplotlib copied to clipboard
Aspect ratio not exported
I am trying to preserve the aspect ratio being set for my figure, but it seems to be ignored. At the moment I manually add height=5cm,width=5cm to the axis argument (or specify it using the extra_axis_parameters), but an automated solution would probably be better as the docs for the figurewidth and figureheight explicitly state that not specifying them will try to preserve the aspect ratio - which seems to fail in my case.
Python code:
import matplotlib.pyplot as plt
import tikzplotlib
circle = plt.Circle((0, 0), 1)
figure, axes = plt.subplots(figsize=(5, 5))
axes.set_xlim([-1.5, 1.5])
axes.set_ylim([-1.5, 1.5])
axes.set_aspect("equal", adjustable="box")
axes.add_artist(circle)
figure.savefig("correct_output.png")
tikzplotlib.save(figure=figure, filepath="output.tex", standalone=True)
Exported LaTeX code:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\DeclareUnicodeCharacter{2212}{−}
\begin{document}
% This file was created by tikzplotlib v0.8.1.
\begin{tikzpicture}
\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={white!69.01960784313725!black},
xmin=-1.5, xmax=1.5,
xtick style={color=black},
y grid style={white!69.01960784313725!black},
ymin=-1.5, ymax=1.5,
ytick style={color=black}
]
\draw[fill=color0,draw opacity=0] (axis cs:0,0) circle (1);
\end{axis}
\end{tikzpicture}
\end{document}
I have the same problem. When I use plt.axis('equal') and export the file to TeX, I get a distorted image in my document.
I am also facing the same problem.
I also have this problem.
+1, same issue.
+1.
Successful workaround in tikzplotlib v0.9.4:
tikzplotlib.save("file_name.tex", extra_axis_parameters=['axis equal'])
extra_axis_parameters=['axis equal image'] worked. See https://tex.stackexchange.com/questions/227759/pgfplots-axis-limits-and-axis-equal