![2 个审查标记,2 种不同颜色](https://linux22.com/image/304425/2%20%E4%B8%AA%E5%AE%A1%E6%9F%A5%E6%A0%87%E8%AE%B0%EF%BC%8C2%20%E7%A7%8D%E4%B8%8D%E5%90%8C%E9%A2%9C%E8%89%B2.png)
我正在尝试创建一个包含两个分布、两个不同的审查点和两种不同颜色的图。我已成功创建了两个分布并赋予它们不同的颜色。我还创建了两个审查点,但无法将其中一个审查点的颜色更改为红色。我尝试了几种组合,但似乎总是将两个审查点绘制在同一颜色下。有什么建议吗?我附上了一张图片和代码。非常感谢!
\begin{frame}
\frametitle{Insert title}
\begin{figure}[!ht]
\begin{center}
\begin{tikzpicture}[
declare function={gamma(\z)=
2.506628274631*sqrt(1/\z)+ 0.20888568*(1/\z)^(1.5)+ 0.00870357*(1/\z)^(2.5)- (174.2106599*(1/\z)^(3.5))/25920- (715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;},
declare function={gammapdf(\x,\k,\theta) = 1/(\theta^\k)*1/(gamma(\k))*\x^(\k-1)*exp(-\x/\theta);}
% declare function={gammapdf(\x,\k,\theta) = 1/(\theta^\k)*1/(gamma(\k))*\x^(\k-1)*exp(-\x/\theta);}
]
\begin{axis}[
no markers, domain=0:7.0, samples=100,
axis lines=left, xlabel=$y_t^i$, ylabel=$f_y(.)$,
every axis y label/.style={at=(current axis.above origin),anchor=east},
every axis x label/.style={at=(current axis.right of origin),anchor=north},
major x grid style={draw=cyan!50!cyan},
height=6cm, width=11cm,
%xtick={6.5},
xtick style={color=cyan},
xtick={6.0,6.5},
ytick=\empty,
%xticklabels={},
xticklabels={$\bar y$, $\bar y'$},
%xticklabels={$\bar n(\theta_t)$},
%xticklabels={$\bar n$, $\bar n$},
%xticklabels={$\bar n(\theta^2_t$), $\bar n(\theta^1_t)$},
enlargelimits=false, clip=false, axis on top,
grid = major,
xmax=10
]
\addplot [very thick,red!50!red,domain=0:6.5] {gammapdf(x,9,0.5)};
\addplot [very thick,cyan!50!cyan,domain=0:6] {gammapdf(x+0.5,9,0.5)};
%\addplot [fill=cyan!20, draw=none, domain=0:6.5] {gammapdf(x,9,0.5)} \closedcycle;
\end{axis}
\end{tikzpicture}
\end{center}
\caption{Insert Caption}
\end{figure}
\end{frame}
答案1
您正在使用(可能滥用)网格来绘制审查点,并且每个网格(major
和minor
)都有一种样式;不能只针对其中的一部分进行更改grid
。
最初的可能性是,xtick
一个审查点使用 ,extra x ticks
另一个审查点使用 。一个可以使用major
网格样式,另一个可以使用独立设置的minor
网格样式。
但这种方法很笨拙,如果要绘制的审查点超过 2 个,或者你想做更复杂的造型,这种方法就会失效。所以,在这种情况下,我认为最简单的方法是手动绘制审查点,方法是
\draw[cyan] (6.0,0) -- ++(rel axis cs:0,1);
\draw[red] (6.5,0) -- ++(rel axis cs:0,1);
自动绘制rel axis cs:0,1
到轴“框”的顶部,无论缩放比例和/或限制如何。
你甚至可以用命令来做到这一点;比如
\newcommand{\censorpt}[2][]{\draw[#1] (#2,0) -- ++(rel axis cs:0,1);}
用作\censorpt[dashed,green]{5.5}
。
我还删除了多余的颜色混合(red!50!red
相当于red
)并添加了typeset ticklabels with strut
以便更好地对齐刻度标签。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\newcommand{\censorpt}[2][]{\draw[#1] (#2,0) -- ++(rel axis cs:0,1);}
\begin{document}
\begin{tikzpicture}[
declare function={gamma(\z)=
2.506628274631*sqrt(1/\z)+ 0.20888568*(1/\z)^(1.5)+ 0.00870357*(1/\z)^(2.5)- (174.2106599*(1/\z)^(3.5))/25920- (715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;},
declare function={gammapdf(\x,\k,\theta) = 1/(\theta^\k)*1/(gamma(\k))*\x^(\k-1)*exp(-\x/\theta);}
]
\begin{axis}[
no markers, domain=0:7.0, samples=100,
axis lines=left, xlabel=$y_t^i$, ylabel=$f_y(.)$,
every axis y label/.style={at=(current axis.above origin),anchor=east},
every axis x label/.style={at=(current axis.right of origin),anchor=north},
major x grid style={draw=cyan},
height=6cm, width=11cm,
%xtick={6.5},
xtick={6.0,6.5},
ytick=\empty,
%xticklabels={},
xticklabels={$\bar y$, $\bar y'$},
%xticklabels={$\bar n(\theta_t)$},
%xticklabels={$\bar n$, $\bar n$},
%xticklabels={$\bar n(\theta^2_t$), $\bar n(\theta^1_t)$},
enlargelimits=false, clip=false, axis on top,
xmax=10,
typeset ticklabels with strut,
]
\addplot [very thick,red,domain=0:6.5] {gammapdf(x,9,0.5)};
\addplot [very thick,cyan,domain=0:6] {gammapdf(x+0.5,9,0.5)};
\draw[cyan] (6.0,0) -- ++(rel axis cs:0,1);
\draw[red] (6.5,0) -- ++(rel axis cs:0,1);
\censorpt[green,dashed]{5.5}
\end{axis}
\end{tikzpicture}
\end{document}
键typeset ticklabels with strut
和默认axis cs
坐标系是 v1.11 的一部分pgfplots
。如果出于某种原因仍使用旧版本,您可以使用
\documentclass{standalone}
\usepackage{pgfplots}
\newcommand{\censorpt}[2][]{\draw[#1] (axis cs:#2,0) -- ++(rel axis cs:0,1);}
\begin{document}
\begin{tikzpicture}[
declare function={gamma(\z)=
2.506628274631*sqrt(1/\z)+ 0.20888568*(1/\z)^(1.5)+ 0.00870357*(1/\z)^(2.5)- (174.2106599*(1/\z)^(3.5))/25920- (715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;},
declare function={gammapdf(\x,\k,\theta) = 1/(\theta^\k)*1/(gamma(\k))*\x^(\k-1)*exp(-\x/\theta);}
]
\begin{axis}[
no markers, domain=0:7.0, samples=100,
axis lines=left, xlabel=$y_t^i$, ylabel=$f_y(.)$,
every axis y label/.style={at=(current axis.above origin),anchor=east},
every axis x label/.style={at=(current axis.right of origin),anchor=north},
major x grid style={draw=cyan},
height=6cm, width=11cm,
%xtick={6.5},
xtick={6.0,6.5},
ytick=\empty,
%xticklabels={},
xticklabels={$\bar y$, $\bar y'$},
%xticklabels={$\bar n(\theta_t)$},
%xticklabels={$\bar n$, $\bar n$},
%xticklabels={$\bar n(\theta^2_t$), $\bar n(\theta^1_t)$},
enlargelimits=false, clip=false, axis on top,
xmax=10,
]
\addplot [very thick,red,domain=0:6.5] {gammapdf(x,9,0.5)};
\addplot [very thick,cyan,domain=0:6] {gammapdf(x+0.5,9,0.5)};
\draw[cyan] (axis cs:6.0,0) -- ++(rel axis cs:0,1);
\draw[red] (axis cs:6.5,0) -- ++(rel axis cs:0,1);
\censorpt[green,dashed]{5.5}
\end{axis}
\end{tikzpicture}
\end{document}
其中typeset ticklabels with strut
被删除并且axis cs:
作为坐标的前缀。