我正在尝试创建一个在 X 轴上用文本代替数字的折线图,但无法做到。以下是我的 MWE。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{verbatim}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
xmin=0, xmax=30,
ymin=0, ymax=100,
xtick={10,20,30},
ytick={10,20,30,40,50,60,70,80,90,100}
]
\addplot[smooth,mark=*,blue] plot coordinates {
(0,10)
(8,30)
(16,40)
};
\addlegendentry{Case 1}
\addplot[smooth,color=red,mark=x]
plot coordinates {
(4,15)
(10,25)
(15,40)
(18,60)
};
\addlegendentry{Case 2}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
xmin=0, xmax=30,
ymin=0, ymax=100,
xtick={10,20,30},
xticklabels={A,B,X}, % <---
ytick={0,10,...,100}
]
\addplot[smooth,mark=*,blue] plot coordinates {
(0,10)
(8,30)
(16,40)
};
\addlegendentry{Case 1}
\addplot[smooth,color=red,mark=x]
plot coordinates {
(4,15)
(10,25)
(15,40)
(18,60)
};
\addlegendentry{Case 2}
\end{axis}
\end{tikzpicture}
\end{document}