这是我得到的。
\begin{tikzpicture}[scale=1.2]
\begin{axis}[
xmax=20,xmin=4,
ymin=0,ymax=0.6,
xlabel=\emph{Number},ylabel=\emph{F1 Score},
xtick={20,16,...,4},
ytick={0,0.1,0.20,...,0.6},
x dir=reverse,
]
\addplot+ [mark=pentagon*,mark size=2.5pt,every mark/.append style={}] coordinates{(20, 0.37) (16, 0.33) (12, 0.29) (8, 0.23) (4, 0.21)};
\addplot coordinates{(20, 0.46) (16, 0.45) (12, 0.45) (8, 0.43) (4, 0.42)};
\end{axis}
\end{tikzpicture}%
但我想要这个
答案1
一个非常简单的方法是明确添加标签。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.2]
\begin{axis}[
xmax=20,xmin=4,
ymin=0,ymax=0.6,
xlabel=\emph{Number},ylabel=\emph{F1 Score},
xtick={20,16,...,4},
xticklabels={$4\cdot5$,$4\cdot4$,$4\cdot3$,$4\cdot2$,$4\cdot1$},
xticklabel style={yshift=-0.3ex},
ytick={0,0.1,0.20,...,0.6},
x dir=reverse,
]
\addplot+ [mark=pentagon*,mark size=2.5pt,every mark/.append style={}] coordinates{(20, 0.37) (16, 0.33) (12, 0.29) (8, 0.23) (4, 0.21)};
\addplot coordinates{(20, 0.46) (16, 0.45) (12, 0.45) (8, 0.43) (4, 0.42)};
\end{axis}
\end{tikzpicture}%
\end{document}
您也可以重新定义xticklabel
为成为xticklabel={$\pgfmathtruncatemacro{\myx}{\tick/4}\myx\cdot4$}
。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.2]
\begin{axis}[
xmax=20,xmin=4,
ymin=0,ymax=0.6,
xlabel=\emph{Number},ylabel=\emph{F1 Score},
xtick={20,16,...,4},
xticklabel={$\pgfmathtruncatemacro{\myx}{\tick/4}\myx\cdot4$},
xticklabel style={yshift=-0.3ex},
ytick={0,0.1,0.20,...,0.6},
x dir=reverse,
]
\addplot+ [mark=pentagon*,mark size=2.5pt,every mark/.append style={}] coordinates{(20, 0.37) (16, 0.33) (12, 0.29) (8, 0.23) (4, 0.21)};
\addplot coordinates{(20, 0.46) (16, 0.45) (12, 0.45) (8, 0.43) (4, 0.42)};
\end{axis}
\end{tikzpicture}%
\end{document}