由于使用的是中文,因此我们可以将中文标签转换为垂直标签,只需调整标签的宽度即可。如果不更改字体大小,它将使标签位于主要刻度的中心,因此效果很好。例如:
\documentclass{article}
\usepackage{tikz,ctex}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[showframe]{geometry}
%\usetikzlibrary{calc,shapes.arrows,datavisualization,arrows.meta,decorations.pathmorphing,backgrounds,positioning,fit,petri,decorations.pathreplacing}
\begin{document}
\begin{figure}
\hfill
\begin{tikzpicture}
\begin{axis}[xtick={1,2,3,4,5,6,7,8,9,10,11},xticklabels={第一个,第二个,第三个,第四个,第五个,第六个,第七个,第八个,第九个,第十个,第十一个},xticklabel style={text width=1em},yticklabel style={/pgf/number format/precision =2,/pgf/number format/fixed,/pgf/number format/fixed zerofill},scaled ticks=false,width=7.4cm,height=4cm,xmin=0,xmax=12,ylabel={the first}]
\addplot[
scatter,only marks, point meta=explicit symbolic,
scatter/classes={
a={mark=o,draw=black},
b={mark=square*},
c={mark=triangle*}
},
] table [meta=label]{
x y label
1 0.55476356 c
2 0.363722187 c
3 0.81286394 c
4 0.875783813 c
5 0.315270863 c
6 0.827911581 c
7 0.720070049 c
8 0.347479399 c
9 0.27043531 c
10 0.490422201 c
11 0.69325892 c
1 0.735883237 a
2 0.129003395 a
3 0.461826926 a
4 0.756650854 a
5 0.305755095 a
6 0.263120301 a
7 0.38954705 a
8 0.07894936 a
9 0.984081129 a
10 0.712322139 a
11 0.146583606 a
1 0.186438911 b
2 0.483752955 b
3 0.955453588 b
4 0.931741157 b
5 0.307806207 b
6 0.932585214 b
7 0.390174549 b
8 0.397465905 b
9 0.893646115 b
10 0.177956892 b
11 0.250648427 b
};
\addplot[mark=none, black,dashed,domain=0:12,samples=2] {0.336};
\end{axis}
\end{tikzpicture}
\centering
\begin{tikzpicture}
\begin{axis}[xtick={1,2,3,4,5,6,7,8,9,10,11},xticklabels={第一个,第二个,第三个,第四个,第五个,第六个,第七个,第八个,第九个,第十个,第十一个},xticklabel style={text width=1em,font=\scriptsize},yticklabel style={/pgf/number format/precision =2,/pgf/number format/fixed,/pgf/number format/fixed zerofill},scaled ticks=false,width=7.4cm,height=4cm,xmin=0,xmax=12,ylabel={the second}]
\addplot[
scatter,only marks, point meta=explicit symbolic,
scatter/classes={
a={mark=o,draw=black},
b={mark=square*},
c={mark=triangle*}
},
] table [meta=label]{
x y label
1 0.55476356 c
2 0.363722187 c
3 0.81286394 c
4 0.875783813 c
5 0.315270863 c
6 0.827911581 c
7 0.720070049 c
8 0.347479399 c
9 0.27043531 c
10 0.490422201 c
11 0.69325892 c
1 0.735883237 a
2 0.129003395 a
3 0.461826926 a
4 0.756650854 a
5 0.305755095 a
6 0.263120301 a
7 0.38954705 a
8 0.07894936 a
9 0.984081129 a
10 0.712322139 a
11 0.146583606 a
1 0.186438911 b
2 0.483752955 b
3 0.955453588 b
4 0.931741157 b
5 0.307806207 b
6 0.932585214 b
7 0.390174549 b
8 0.397465905 b
9 0.893646115 b
10 0.177956892 b
11 0.250648427 b
};
\addplot[mark=none, black,dashed,domain=0:12,samples=2] {0.778};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
请使用 XeLaTeX 运行上述代码。
输出:
在第二张图中,如何使标签居中?