0

I want three plots, with a constant Y-value. I need these to be visually comparable, so the Y-axis scale needs to be the same. The three values I'm plotting are: y= {0.3,0.6,0.9}, and my Y-axis should show between 0 and 1.

Here's what I have:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=7cm,
height=5cm,
align=center,
xticklabels={},
ymax = 1.1,xmax=3.5,
axis lines*=center,
ytick={0.5,1},
xtick={1,2,3},
xlabel shift= 0.4cm]
\addplot+[blue,thick,mark=none] coordinates {(0, 0.9) (3, 0.9)};;
\end{axis}
\end{tikzpicture}
\end{document}

This produces:

Plotting y=0.9

And, when I plot y=0.3, I get this:

Plottying y=0.3

The Y-axis looks like it's been scaled: the line appears in the same place in the image, but the axis markings have shifted.

How can I prevent pgfplots from doing this?

1

The axis isn't being scaled - it's being shifted.

The second image gives the impression of an exponential axis scale, because the first mark (0.5) is closer to the X-axis than it is to the second mark (1) - but this is not the case, which can be demonstrated by adding in more tick marks:

enter image description here

To prevent this from occuring, set the ymin to 0:

enter image description here enter image description here

The MWE to produce the second of these corrected plots:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=7cm,
height=5cm,
align=center,
xticklabels={},
ymax = 1.1,xmax=3.5,
ymin = 0, xmin = 0,
axis lines*=center,
ytick={0.25, 0.5,0.75, 1},
xtick={1,2,3},
xlabel shift= 0.4cm]
\addplot+[blue,thick,mark=none] coordinates {(0, 0.9) (3, 0.9)};;
\end{axis}
\end{tikzpicture}
\end{document}

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.