这是我的代码:
\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}