我正在写论文,所以我用这个standalone
包来生成pgfplots
图表的 PDF,然后把它们放到主文档中。不过,我在绘制一个图时遇到了一些问题,下面是代码
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={2,3.4,4.8,6.2,7.6},
xtick distance=1,
xlabel={$d$ (mm)},
ylabel={Stiffness (N/m)},
ytick={0,800,16000,24000,36000}, %<-These should be the y-axis tick positions
yticklabels={0,800,1600,24000,32000}, %<-These should be the y-axis labels
x label style={at={(axis description cs:0.5,0.2)},anchor=north},
y label style={at={(axis description cs:0.1,0.5)},anchor=north},
width=0.33\textwidth,
tick label style={font=\tiny},
label style={font=\scriptsize},
]
\addplot
table[row sep=crcr,x index=0,y index=1] {
2 13.914777\\
3.4 116.21761\\
4.8 461.65892\\
6.2 1285.0589\\
7.6 2901.4203\\
};
\end{axis}
\end{tikzpicture}
\end{document}
当我编译它时,我得到以下内容:
ytick
我不知道为什么会发生这种情况,我尝试改变和线 的位置yticklabels
但无济于事。
答案1
标签按预期工作。只是除了ytick={0,800,16000,24000,36000}
前两个条目之外,其余条目都超出了绘图范围。如果你删除这些条目末尾的零,你会得到
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={2,3.4,4.8,6.2,7.6},
xtick distance=1,
xlabel={$d$ (mm)},
ylabel={Stiffness (N/m)},
ytick={0,800,1600,2400,3600}, %<-These should be the y-axis tick positions
yticklabels={0,800,1600,24000,32000}, %<-These should be the y-axis labels
x label style={at={(axis description cs:0.5,0.2)},anchor=north},
y label style={at={(axis description cs:0.1,0.5)},anchor=north},
width=0.33\textwidth,
tick label style={font=\tiny},
label style={font=\scriptsize},
]
\addplot
table[row sep=crcr,x index=0,y index=1] {
2 13.914777\\
3.4 116.21761\\
4.8 461.65892\\
6.2 1285.0589\\
7.6 2901.4203\\
};
\end{axis}
\end{tikzpicture}
\end{document}
如果刻度标签中的逗号让您感到困扰,您可以使用 将其删除pgf/number format/set thousands separator={}
。
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={2,3.4,4.8,6.2,7.6},
xtick distance=1,
xlabel={$d$ (mm)},
ylabel={Stiffness (N/m)},
ytick={0,800,1600,2400,3600}, %<-These should be the y-axis tick positions
width=0.33\textwidth,
tick label style={font=\tiny},
label style={font=\scriptsize,/pgf/number format/set thousands separator={}},
]
\addplot
table[row sep=crcr,x index=0,y index=1] {
2 13.914777\\
3.4 116.21761\\
4.8 461.65892\\
6.2 1285.0589\\
7.6 2901.4203\\
};
\end{axis}
\end{tikzpicture}
\end{document}