Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using code below to create a graph. On the bottom there are two braces denoted $t_1$ and $t_2$. However numbers 1 and 2 are broken (lower part is not displayed). What is wrong with my code? I also tried to solve this problem using \pgfplotsextra to no awail.

Also, related to the code below, I would like to put into .style that all graphs have limit enlarged by fixed distance, i.e. 1 cm. If I understand the question Enlarge limits by absolute value when using symbolic coordinates right, this is not possible at all?

\documentclass[12pt,a7paper,landscape]{scrartcl}
\usepackage{pgfplots}

\pgfplotsset{standard/.style={axis x line=middle,axis y line=middle,every axis x label/.style={at={(current axis.right of origin)},anchor=north},every axis y label/.style={at={(current axis.above origin)},anchor=east}}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[standard,width=8cm,height=5cm,enlarge x limits=0.11,enlarge y limits=0.19,xlabel=$t$,ylabel=$v$,xtick={20,60},xticklabels={,},ytick={25},yticklabels={$v'$}]

\addplot[thick,color=black] coordinates { (0,0) (20,25) (60,25) };
\addplot[dashed,very thin,color=black] coordinates { (20,0) (20,25) (0,25) };
\addplot[dashed,very thin,color=black] coordinates { (60,0) (60,25) };

\node at (axis cs:13.3,8.3) {$s_1$};
\node at (axis cs:40,12.5) {$s_2$};

\draw [decorate,decoration={brace,mirror,raise=2pt}] (axis cs:0,0) -- (axis cs:20,0) node [midway,below=1pt] {$t_1$};
\draw [decorate,decoration={brace,mirror,raise=2pt}] (axis cs:20,0) -- (axis cs:60,0) node [midway,below=1pt] {$t_2$};

\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

share|improve this question
1  
In your screenshot, and when I compile your code, the subscript 1 and 2 below the x axis look fine. Could you include a larger screenshot? –  Jake Aug 29 '12 at 12:25
    
I can see the problem. And if I remove the axis x line=middle in the standard style a line appears which goes throught the bottom of the 2. With enlarge y limits=0.22 (a larger value) this line moves down and your problem disappears. –  Ulrike Fischer Aug 29 '12 at 13:01
    
@Jake I don't know how to do it. Publishing latex pictures on stackexchange is horrible pain in the ass, I always have problems with that. –  Pygmalion Aug 29 '12 at 13:22
    
@UlrikeFischer I am aware of that patch, but I do not want to extend limits. Even now they are too extended. –  Pygmalion Aug 29 '12 at 13:23
    
@Pygmalion: Ah, I could see it at different zoom levels. –  Jake Aug 29 '12 at 13:35
show 2 more comments

1 Answer 1

up vote 3 down vote accepted

The text gets clipped at the edge of the axis area. To prevent this, you can either provide the key clip=false to the axis options, or put the \draw commands in the after end axis/.code={...} to draw the annotations outside the clipping scope:

\documentclass[12pt,a7paper,landscape]{scrartcl}
\usepackage{pgfplots}

\pgfplotsset{standard/.style={axis x line=middle,axis y line=middle,every axis x label/.style={at={(current axis.right of origin)},anchor=north},every axis y label/.style={at={(current axis.above origin)},anchor=east}}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    standard,
    width=8cm,height=5cm,
    enlarge x limits=0.11,enlarge y limits=0.19,
    xlabel=$t$,ylabel=$v$,
    xtick={20,60},xticklabels={,},
    ytick={25},yticklabels={$v'$},
    after end axis/.code={
        \draw [decorate,decoration={brace,mirror,raise=2pt}] (axis cs:0,0) -- (axis cs:20,0) node [midway,below=1pt] {$t_1$};
        \draw [decorate,decoration={brace,mirror,raise=2pt}] (axis cs:20,0) -- (axis cs:60,0) node [midway,below=1pt] {$t_2$};
    }
]

\addplot[thick,color=black] coordinates { (0,0) (20,25) (60,25) };
\addplot[dashed,very thin,color=black] coordinates { (20,0) (20,25) (0,25) };
\addplot[dashed,very thin,color=black] coordinates { (60,0) (60,25) };

\node at (axis cs:13.3,8.3) {$s_1$};
\node at (axis cs:40,12.5) {$s_2$};

\end{axis} 
\end{tikzpicture}
\end{document}
share|improve this answer
    
I like clip=false better, because I hate options that are half a page long. If there is no drawbacks, I stick to that. –  Pygmalion Aug 29 '12 at 15:40
    
BTW, is there any way to put enlarge axis limits in cm, possibly in \pgfplotsset{standard/.style={...? –  Pygmalion Aug 29 '12 at 15:42
    
@Pygmalion: There are drawbacks. If you're plotting data that extends beyond the xmin and xmax limits, the graph won't be clipped if you set clip=false. I'd go with the after end axis/.code. If you don't want to supply such a long option in the axis options, you can also just call \pgfplotsset{after end axis/.code={ \draw ... } } at the place where you now have your \draw commands. –  Jake Aug 29 '12 at 15:44
    
@Pygmalion: I'd suggest opening a new question for that. –  Jake Aug 29 '12 at 15:44
    
I'll do that later. I feel so embarrased by opening dozens of questions on pgfplot only. Seems that I am so confused about that package... –  Pygmalion Aug 29 '12 at 15:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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