# Axis scaling issue with external graphics

I was referring to the following posts

I was trying to fit my image in a defined axis. Unfortunately, the image is not scaling correctly(aspect ratio always changes). The image is as below,(i take it as a pdf for my tikz picture)

MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%small,
axis equal image,
enlargelimits=false,
axis on top,
axis equal=false
]
\end{axis}
\end{tikzpicture}
\end{document}


And the not so MWE version(if needed)

%\documentclass{standalone}
%
%\usepackage{pgfplots}
%
%\begin{document}
%  \begin{tikzpicture}
%    \begin{axis}[
%        axis on top,% ----
%        width=5cm,
%        scale only axis,
%        enlargelimits=false,
%        xmin=0,xmax=10,
%        xlabel={Length($mm$)},
%        xtick={0,2,4,6,8,10},
%        xticklabels={0,2,4,6,8,10},
%           scaled ticks=false,
%           axis equal image,
%        ymin=0,ymax=2,
%        ylabel={Length($mm$)},
%        ytick={0.1,0.5 ,1,1.5,2},
%        yticklabels={0.1,0.5 ,1,1.5,2},
%        axis equal=false,
%        axis equal image,
%        ]
%
%    \end{axis}
%  \end{tikzpicture}
%\end{document}

• We need code we can use to reproduce the problem. Since only you have fig1.pdf, nobody but you can compile the code to diagnose or troubleshoot. – cfr Aug 17 '17 at 10:51
• I copied your image and it worked fine. You do realize that axis equal image and axis equal=false cancel, and neither is needed. If you want a specific aspect ratio, set the width and height using scale axis only. – John Kormylo Aug 17 '17 at 16:06
• BTW, the default size of this image is about 97 by 45 inches. It still works but the tick labels are too small to be visible. – John Kormylo Aug 17 '17 at 16:18

The following preserves the original aspect ratio, but scales it down to a given width (4in). You will need to change the pathname for your system.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\sbox0{\includegraphics[width=4in]{images/7PuiQ}}%

\begin{tikzpicture}
\begin{axis}[%small,
scale only axis, width={\wd0}, height={\ht0},
enlargelimits=false,% not needed
axis on top,
]