![使用 pgfplots 绘制具有不同基值的直方图?](https://linux22.com/image/274287/%E4%BD%BF%E7%94%A8%20pgfplots%20%E7%BB%98%E5%88%B6%E5%85%B7%E6%9C%89%E4%B8%8D%E5%90%8C%E5%9F%BA%E5%80%BC%E7%9A%84%E7%9B%B4%E6%96%B9%E5%9B%BE%EF%BC%9F.png)
如何绘制以 -60 为基值而不是 0(默认值)的以下条形图?
\documentclass[convert={density=400,outext=.png}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[baseline]
\centering
\begin{axis}[ybar,bar width=1,line width=2,
ylabel=Output Power(dBm),
xlabel=Frequency(GHz),label style={font=\bfseries\LARGE},
legend style={legend pos= south east},
tick label style={font=\bfseries\Large},
grid=major,anchor=north]
\addplot coordinates
{(100,-24)(200,5.5)(300,-55)(400,-9.5)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我不太清楚你所说的基数是什么意思,但有一种可能性是将相对值转移到-60
\documentclass[convert={density=400,outext=.png}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[baseline]
\centering
\begin{axis}[
ybar,
bar width=1,
line width=2,
ylabel=Output Power(dBm),
xlabel=Frequency(GHz),
label style={font=\bfseries\LARGE},
legend style={legend pos= south east},
tick label style={font=\bfseries\Large},
grid=major,
anchor=north,
y coord trafo/.code={\pgfmathparse{#1+60}}, % Addition
y coord inv trafo/.code={\pgfmathparse{#1-60}} % Addition
]
\addplot coordinates{(100,-24)(200,5.5)(300,-55)(400,-9.5)};
\end{axis}
\end{tikzpicture}
\end{document}