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 try/want to color the x-axes in a special way. I want to get the bottom x-axis red, but not the whole line. Only the 3 parts under the graph have to be colored. I tried it with options

separate axis lines,
every outer x axis line/.append style={-stealth,red},

but both x-axes completely get red. Is there a possibility to get what I want?

enter image description here

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,backgrounds,fit,shapes,decorations.pathreplacing}
\usepackage{pgfplots}


\begin{document}

\centering
\begin{tikzpicture}
\begin{axis}[xlabel style={align=right},xlabel=Output (MW),
ylabel=Input (\$/h),unbounded coords=jump, xtick={0,1,2,3,4,5,6,7,8,9},  xticklabel style={anchor=base,yshift=-\baselineskip},ytick=\empty,xtick=\empty,extra x ticks={0,2,4,6,8,9},extra x tick labels={,$P_{pz}^-$,$P_{pz}^+$,,,}]
\addplot+[black,smooth,no markers] coordinates {
(0,0) (1,1) (2,4) (3,inf)
(4,16) (5,25) (6,36) (7,inf) (8,64) (9,81)
};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this question
1  
You can use \draw[red!70!black,ultra thick] ({axis cs:0,0}|-{axis description cs:0,0}) -- ({axis cs:2,0}|-{axis description cs:0,0}); \draw[red!70!black,ultra thick] ({axis cs:4,0}|-{axis description cs:0,0}) -- ({axis cs:6,0}|-{axis description cs:0,0}); \draw[red!70!black,ultra thick] ({axis cs:8,0}|-{axis description cs:0,0}) -- ({axis cs:9,0}|-{axis description cs:0,0}); but I'm sure there's a more economical way. –  Gonzalo Medina Apr 29 at 0:24
    
thanks a lot! it works wery good! –  Dmitri Apr 29 at 0:29

1 Answer 1

up vote 4 down vote accepted

Here's an option using the axis description and axis coordinate systems (but I have the feeling that there's a simpler way):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,backgrounds,fit,shapes,decorations.pathreplacing}
\usepackage{pgfplots}

\begin{document}

\centering
\begin{tikzpicture}
\begin{axis}[
  xlabel style={align=right},
  xlabel=Output (MW),
  ylabel=Input (\$/h),
  unbounded coords=jump, 
  xtick={0,1,2,3,4,5,6,7,8,9},  
  xticklabel style={anchor=base,yshift=-\baselineskip},
  ytick=\empty,
  xtick=\empty,
  clip=false,
  extra x ticks={0,2,4,6,8,9},
  extra x tick labels={,$P_{pz}^-$,$P_{pz}^+$,,,}
]
\addplot+[black,smooth,no markers] coordinates {
(0,0) (1,1) (2,4) (3,inf)
(4,16) (5,25) (6,36) (7,inf) (8,64) (9,81)
};

\draw[red!70!black,ultra thick] 
  ({axis cs:0,0}|-{axis description cs:0,0}) -- ({axis cs:2,0}|-{axis description cs:0,0});
\draw[red!70!black,ultra thick] 
  ({axis cs:4,0}|-{axis description cs:0,0}) -- ({axis cs:6,0}|-{axis description cs:0,0});
\draw[red!70!black,ultra thick] 
  ({axis cs:8,0}|-{axis description cs:0,0}) -- ({axis cs:9,0}|-{axis description cs:0,0});
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Thank you! this is even better! –  Dmitri Apr 29 at 0:32

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.