5

I would like to emphasize certain features in plots, by only showing the meaningful parts of the axis, e.g. let's assume I have a plot much like this one: My example plot

Is it possible to draw, say the y-axis, only between two specified points? Similar to what I've hacked together below.

enter image description here


\begin{tikzpicture}

\begin{axis}[%
        axis x line=bottom,
        axis y line=left,
        xmin=0,
        ymin=0
]%
\addplot coordinates {
    (0,0.6)
    (0.1,0.3)
    (1,1)
};
% Axis
\draw[thick] (axis cs:0,0.3) -- (axis cs:0,0.6);
% "Ticks"
\draw (axis cs:0.01,0.3) -- (axis cs:0,0.3);
\draw (axis cs:0.01,0.6) -- (axis cs:0,0.6);

\end{axis}

\end{tikzpicture}
1
  • 2
    You could at least use the rel axis cs so that you can use relative coordinates instead of absolute ones. Commented Aug 23, 2013 at 9:32

1 Answer 1

4

You can adapt the approach from How can I add a zero line to a plot?

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}

\begin{axis}[%
        axis x line=bottom,
        axis y line*=left,
        y axis line style={draw opacity=0},
        xmin=-0.05,
        ymin=0,
        after end axis/.code={
                \draw ({rel axis cs:0,0}|-{axis cs:0,0.3}) --
                    ({rel axis cs:0,0}|-{axis cs:0,0.6});
        }
]%
\addplot coordinates {
    (0,0.6)
    (0.1,0.3)
    (1,1)
};
\end{axis}

\end{tikzpicture}
\end{document}
5
  • Hi @Jake, technically that's a correct answer, but I was hoping there's a way to override the internal axis \draw command, so I'd be able to use all other axis' commands etc. So I'll leave the question open for a couple more days :)
    – kadrach
    Commented Aug 26, 2013 at 2:01
  • Could you edit your question to include some more detail on what kind of options you're thinking about?
    – Jake
    Commented Aug 26, 2013 at 6:57
  • I will try to update the question with more detail later tonight. But to give you a tl;dr, I want it all - all styling options, scaling options, tick options, label options, whatever options there really are for the axis. The only thing I want to change, is to specifically draw the axis only between selected points.
    – kadrach
    Commented Aug 27, 2013 at 2:23
  • @noe: do you want the ticks to only be drawn within the specified interval, or should they still cover the whole axis range?
    – Jake
    Commented Aug 27, 2013 at 6:09
  • I would expect the tick marks only within the region specified, that is, only in the region where the axis is drawn.
    – kadrach
    Commented Aug 27, 2013 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .