该代码几乎可以正常工作。我缺少的是一种将线条连接起来的方法,使其看起来像步骤……
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}
[
xmin=0, xmax=6,
ymin=0, ymax=6,
xlabel={$t$},
ylabel={$\rho$},
axis y line=middle,
axis x line=middle,
]
\addplot [black,domain=0:1, no marks] {6};
\addplot [black,domain=1:2, no marks] {5};
\addplot [black,domain=2:3, no marks] {4};
\addplot [black,domain=3:4, no marks] {3};
\addplot [black,domain=4:5, no marks] {2};
\addplot [black,domain=5:6, no marks] {1};
\end{axis}
\end{tikzpicture}
\caption[some text] {some text}
\label{fig:someLabel}
\end{figure}
\end{document}
提前致谢,托马斯
答案1
喜欢这个吗?Pgfplots 文档,第 4.5.3 节
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}
[
xmin=0, xmax=6,
ymin=0, ymax=6,
xlabel={$t$},
ylabel={$\rho$},
axis y line=middle,
axis x line=middle,
]
\addplot [black,const plot, no marks] coordinates {(0,6) (1,5) (2,4) (3,3) (4,2) (5,1)};
% \addplot [black,domain=1:2, no marks] {5};
% \addplot [black,domain=2:3, no marks] {4};
% \addplot [black,domain=3:4, no marks] {3};
% \addplot [black,domain=4:5, no marks] {2};
% \addplot [black,domain=5:6, no marks] {1};
\end{axis}
\end{tikzpicture}
\caption[some text] {some text}
\label{fig:someLabel}
\end{figure}
\end{document}