![如何在 pgfplots 中正确格式化 X 轴和 Y 轴?](https://linux22.com/image/474214/%E5%A6%82%E4%BD%95%E5%9C%A8%20pgfplots%20%E4%B8%AD%E6%AD%A3%E7%A1%AE%E6%A0%BC%E5%BC%8F%E5%8C%96%20X%20%E8%BD%B4%E5%92%8C%20Y%20%E8%BD%B4%EF%BC%9F.png)
这是我的代码:
\begin{tikzpicture}
\begin{axis}[
xmin=2016, xmax=2023,
ymin=6000, ymax=10000
]
\addplot[smooth,mark=*,blue] plot coordinates {
(2016, 7400)
(2017, 7580)
(2018, 7830)
(2019, 7910)
(2020, 7640)
(2021, 8560)
(2022, 8510)
(2023, 7440)
};
\addlegendentry{Trend}
\end{axis}
\end{tikzpicture}
结果图如下所示:
我想将 X 轴显示为年份(无千位分隔符),Y 轴显示数字,而不是像 0.6 x10 4这样的内容。我错过了什么?
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=2016, xmax=2023,
ymin=6000, ymax=10000,
/pgf/number format/.cd,1000 sep={},
scaled y ticks=false,
]
\addplot[blue, smooth, mark=*] plot coordinates {
(2016, 7400)
(2017, 7580)
(2018, 7830)
(2019, 7910)
(2020, 7640)
(2021, 8560)
(2022, 8510)
(2023, 7440)
};
\addlegendentry{Trend}
\end{axis}
\end{tikzpicture}
\end{document}