0

I was referring to the following posts

1: Image with axis, [2]: pgfplots axis enlargelimits

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)

enter image description here

MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[%small, 
    axis equal image,
    enlargelimits=false,
    axis on top,
    axis equal=false
    ]
    \addplot graphics [xmin=0,ymin=0,xmax=10,ymax=2] {fig1.pdf};
    \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,
%        ]
%
%      \addplot[thick,blue] graphics[xmin=0,ymin=0,xmax=10,ymax=2] {fig1.pdf};
%    \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
0

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,
    ]
    \addplot graphics[xmin=0,ymin=0,xmax=10,ymax=2] {images/7PuiQ};
    \end{axis}
    \end{tikzpicture}
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.