轴部分着色

轴部分着色

我尝试/想要以特殊方式为 x 轴着色。我想让底部的 x 轴变成红色,但不是整条线。只有图表下方的 3 个部分必须着色。我尝试使用选项

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

但两个 x 轴都完全变红了。有可能得到我想要的结果吗?

在此处输入图片描述

\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}

答案1

axis description这是一个使用和坐标系的选项axis(但我觉得还有一种更简单的方法):

\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}

在此处输入图片描述

相关内容