tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

Aspect ratio not exported

Open FriedrichFroebel opened this issue 6 years ago • 6 comments
trafficstars

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}

FriedrichFroebel avatar Jul 25 '19 19:07 FriedrichFroebel

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.

cg-david avatar Sep 06 '19 15:09 cg-david

I am also facing the same problem.

ankitp94 avatar Sep 27 '19 19:09 ankitp94

I also have this problem.

IsabellLehmann avatar Dec 13 '19 12:12 IsabellLehmann

+1, same issue.

kanginthaya avatar May 16 '20 09:05 kanginthaya

+1. Successful workaround in tikzplotlib v0.9.4: tikzplotlib.save("file_name.tex", extra_axis_parameters=['axis equal'])

hairykiwi avatar Sep 11 '20 15:09 hairykiwi

extra_axis_parameters=['axis equal image'] worked. See https://tex.stackexchange.com/questions/227759/pgfplots-axis-limits-and-axis-equal

jasonkena avatar Dec 05 '20 15:12 jasonkena