我想创建一个ycomb plot
具有可见范围的颜色渐变。当我创建时scatter plot
,颜色渐变可以工作,但它不适用于comb plot
,如您在附图中看到的那样。我怎样才能使颜色渐变适用于comb plot
?
\pgfplotsset{
dirac/.style={
mark=triangle*,
mark options={yscale=1.3},
ycomb,
scatter,
visualization depends on={(y-abs(y))/abs(y-abs(y)) \as \sign},
scatter/@pre marker code/.code={\scope[rotate=180*\sign,yshift=-2pt]}
}
}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis line style = {->},
width = 7cm,
height = 5cm,
xmax = 1.5,
xmin = -1.5,
ymax = 1.2,
ymin = -1.2,
xlabel = {$f$},
every axis x label/.style={
at={(ticklabel* cs:1.0)},
anchor=west,
},
xtick=\empty,
axis y line =none,
clip=true,
label style = {font=\footnotesize},
colormap = {visiblelight}{
color=(red)
color=(orange)
color=(yellow)
color=(green)
color=(cyan)
color=(blue)
color=(violet)
}
]
\def\tau{1};
\def\amp{2};
\addplot[dirac,domain=-1:1,samples=13,scatter src=x]
{\amp*exp(\tau*x)/(exp(2*\tau*x)+1)};
\addplot+[scatter,mark=*,only marks,scatter src=x,domain=-1:1,samples=15]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
答案1
经过一番努力,我找到了一种使用quiver plot
和 的解决方法scatter plot
。我将图分成两个不同的图:用quiver plot
我画了垂直线,用scatter plot
我画了箭头。
以下是代码:
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis line style = {->},
width = 12cm,
height = 7cm,
xmax = 1.3,
xmin = -1.3,
ymax = 1.2,
ymin = -1.2,
xlabel = {$f$},
every axis x label/.style={
at={(ticklabel* cs:1.0)},
anchor=west,
},
xtick=\empty,
axis y line =none,
clip=false,
label style = {font=\footnotesize},
colormap = {visiblelight}{
color=(red)
color=(orange)
color=(yellow)
color=(green)
color=(cyan)
color=(blue)
color=(violet)
}
]
\def\tau{2.1};
\def\amp{2};
\def\nop{21};
\addplot[
quiver={u=0,v=-\amp*exp(\tau*x)/(exp(2*\tau*x)+1),colored},
domain=-1:1,samples=\nop,scatter src=x]
{\amp*exp(\tau*x)/(exp(2*\tau*x)+1)};
\addplot+[scatter,scatter src=x,mark=triangle*,mark options={yscale=1.3},only marks,domain=-1:1,samples=\nop]
{\amp*exp(\tau*x)/(exp(2*\tau*x)+1)};
\end{axis}
\end{tikzpicture}