![使用 pgfplots 制作的图上不显示刻度的问题](https://linux22.com/image/340886/%E4%BD%BF%E7%94%A8%20pgfplots%20%E5%88%B6%E4%BD%9C%E7%9A%84%E5%9B%BE%E4%B8%8A%E4%B8%8D%E6%98%BE%E7%A4%BA%E5%88%BB%E5%BA%A6%E7%9A%84%E9%97%AE%E9%A2%98.png)
我正在创建一些工业疲劳图,但在 MWE 上,勾号和勾号标签“C”没有出现,我不知道为什么以及如何纠正这个问题。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=1.5.1}
\usepackage{caption}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title= {Fatigue test results per configuration.},
y tick label style={
/pgf/number format/.cd,
fixed,
1000 sep={\thinspace},
precision=0,
/tikz/.cd
},
only marks,enlargelimits=0.15,
xlabel={Configuration style},ylabel={Cycles before failure},
symbolic x coords={A,C}, xtick=data,]
\addplot coordinates {(A,1362)(A,2840) (A,687)(A,2771)};
\addplot coordinates {(C,2130)(C,3544) (C,1844)(C,3447)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
xtick=data
仅使用第一个\addplot
命令来确定刻度位置。您应该改用xtick={A,C}
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=1.5.1}
\usepackage{caption}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title= {Fatigue test results per configuration.},
y tick label style={
/pgf/number format/.cd,
fixed,
1000 sep={\thinspace},
precision=0,
/tikz/.cd
},
only marks,enlargelimits=0.15,
xlabel={Configuration style},ylabel={Cycles before failure},
symbolic x coords={A,C}, xtick={A,C}]
\addplot coordinates {(A,1362)(A,2840) (A,687)
(A,2771)};
\addplot coordinates {(C,2130)(C,3544) (C,1844)(C,3447)};
\end{axis}
\end{tikzpicture}
\end{document}