如何在 PGFPlots 图中的每个 x 值处放置一个点(标记)?
例如,我有以下图表:
由以下代码生成:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable} % For \pgfplotstableread
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}[baseline,trim axis left,trim axis right]
\begin{axis}[
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
enlargelimits=true,
minor tick num=1,
width=\textwidth,
ylabel near ticks,
xlabel near ticks,
ytick={0,0.25,...,1},
xtick={0,1,...,4},
ylabel={Weight $w$},
xlabel={Slot $s$},
]
\addplot[domain=0:4,dashed]{0.31622776601683794^x};
\addplot[domain=0:4.0001,thick,const plot]{0.31622776601683794^floor(x)};
\end{axis}
\end{tikzpicture}
\end{document}
我尝试使用几个mark
原语,标记步骤,标记阶段,但无法产生所需的输出。所需输出:
答案1
samples=5
只需添加代码即可完成,甚至可以做得更简单一些。
有关更多详细信息,请查看代码中的注释。
% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
% use this `compat' level or higher to make use of the advanced positioning of labels
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
ylabel={Weight $w$},
xlabel={Slot $s$},
% it is much simpler to use this key instead of defining the list
xtick distance=1,
minor tick num=1,
]
\addplot [
domain=0:4,
dashed,
] {0.31622776601683794^x};
\addplot [
% define the marker you want to use ...
mark=*,
% ... and how it shall look like
mark options={
color=orange,
},
% there is no need to use another domain here
% (so you can move it to the axis options and delete it
% in the two `\addplot' options
domain=0:4,
% it seems you only want the values at the integers, so
% define an appropriate number of samples
samples=5,
% and you want the marker on the left of the `const plot'
const plot mark left,
thick,
% done all of the above there is no need for the floor function
] {0.31622776601683794^(x)};
\end{axis}
\end{tikzpicture}
\end{document}