使用 PFGPlots 时,如何显示单位(如 ms)而不是 10⁻³?
通常我会从 CSV 文件加载数据,在绘制之前将其从秒缩放到毫秒左右,这是我想要避免的额外步骤。
下面是一个有用的绘图示例:
\documentclass[]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{figure}\centering
\begin{tikzpicture}
\begin{axis}[
title={$V_{{out}}$ versus $t$},
xlabel={$t$},
ylabel={$V_{{out}}$}]
\addplot[color=red,mark=x] coordinates {
(0.0001,-1.531)
(0.0002,-1.6065)
(0.0003,-1.7963)
(0.0004,-2.5868)
(0.0005,-4.0210)
(0.0006, -4.531)
(0.0007,-7.3352)
(0.0008,-11.5088)
(0.0009,-16.1195)
(0.0010,-21.2523)
(0.0011,-26.3903)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
这就是这个pgfplots
库units
的好处。除了加载这个库之外,重要的变化是附加的键change x base,x SI prefix=milli,x unit=s,
。(我也改成了out
直立的。)
\documentclass[]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{units}
\begin{document}
\begin{figure}\centering
\begin{tikzpicture}
\begin{axis}[
title={$V_\mathrm{out}$ versus $t$},
xlabel={$t$},
change x base,
x SI prefix=milli,x unit=s,
ylabel={$V_\mathrm{out}$},
]
\addplot[color=red,mark=x] coordinates {
(0.0001,-1.531)
(0.0002,-1.6065)
(0.0003,-1.7963)
(0.0004,-2.5868)
(0.0005,-4.0210)
(0.0006, -4.531)
(0.0007,-7.3352)
(0.0008,-11.5088)
(0.0009,-16.1195)
(0.0010,-21.2523)
(0.0011,-26.3903)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}