我想绘制一个线图。坐标 y 的值从 0 到 0.035。
但是,y 标签刻度完全错误,有重复值,例如有两个“0.03”标签。因此,绘图当然也是错误的。
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{width=0.9\textwidth,compat=newest}
\begin{tikzpicture}
\begin{axis}
[
axis lines = left,
xlabel = Instance,
ylabel = {Average Deviation (\%)},
scaled y ticks=false,
y tick label style={/pgf/number format/fixed, /pgf/number format/precision=2},
symbolic x coords={1,2,3,4,5,6,7,8,9,10,11},
xtick=data,
xticklabels={$10\times5EG$,$10\times5EH$,$10\times5FH$,$12\times3EG$,$12\times3EH$,$12\times3FG$,$12\times3FH$,$12\times4EG$,$12\times4EH$,$12\times4FG$,$12\times5EG$},
]
\addplot
[
color=red,
mark=square
]
coordinates{(1,0.019)(2,0.029)(3,0.000)(4,0.015)(5,0.003)(6,0.000)(7,0.000)(8,0.035)(9,0.000)(10,0.012)(11,0.004)};
\legend{MBBOTS algorithm}
\end{axis}
\end{tikzpicture}
\end{document}
感谢帮助。
答案1
这里有几点。
你不需要
symbolic x coords={1,2,3,4,5,6,7,8,9,10,11}, xtick=data
提高精度
/pgf/number format/precision=5
。现在由于您使用低精度0.015
,因此0.02
显示相同。您有较长的 xtick 标签。因此,旋转它们将是一个好主意。
有了这些,我们就有:
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{width=0.9\textwidth,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines = left,
xlabel = Instance,
ylabel = {Average Deviation (\%)},
scaled y ticks=false,
y tick label style={/pgf/number format/fixed, /pgf/number format/precision=5},
%symbolic x coords={1,2,3,4,5,6,7,8,9,10,11},
%xtick=data,
x tick label style= {rotate=45,anchor=north east},
xticklabels={$10\times5EG$,$10\times5EH$,$10\times5FH$,$12\times3EG$,$12\times3EH$,$12\times3FG$,$12\times3FH$,$12\times4EG$,$12\times4EH$,$12\times4FG$,$12\times5EG$},
]
\addplot
[
color=red,
mark=square
]
coordinates{(1,0.019)(2,0.029)(3,0.000)(4,0.015)(5,0.003)(6,0.000)(7,0.000)(8,0.035)(9,0.000)(10,0.012)(11,0.004)};
\legend{MBBOTS algorithm}
\end{axis}
\end{tikzpicture}
\end{document}