我正在尝试绘制具有以下 x 值的图形:
0.01、0.05、0.1、0.2、0.3、0.5、0.6、0.7、0.8 和 0.9
当我将它们设置为 xtick 值时,数字会被推到左侧,因为它们的增长速率不同。我想知道是否有办法让这些值与 x 轴正确对齐。
它看起来是这样的,我的代码如下:
\begin{tikzpicture}
\begin{axis}[
title={Throughput vs. Arrival Rate (N = 10)},
xlabel={$\lambda$ (Arrival Rate)},
ylabel={Throughput},
xmin=0.01, xmax=0.9,
ymin=0, ymax=10,
xtick={0.01,0.05,0.1,0.2,0.3,0.5,0.6,0.7,0.8,0.9},
ytick={0,1,2,3,4,5,6,7,8,9,10},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
% Simulated
\addplot[
color=blue,
mark=square,
line width = 1.2pt,
]
coordinates {
(0.01,0.111)(0.05,0.0833)(0.1,0.267)(0.2,0.672)(0.3,1.027)(0.5, 3.2)(0.6, 8.1)(0.7,3.2)(0.8, 0)(0.9,0)
};
\end{axis}
\end{tikzpicture}
答案1
我不太明白你在这里所说的“正确”是什么意思,如果你想要刻度均匀分布,请使用symbolic x coords
:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Throughput vs. Arrival Rate (N = 10)},
xlabel={$\lambda$ (Arrival Rate)},
ylabel={Throughput},
xmin=0.01, xmax=0.9,
ymin=0, ymax=10,
symbolic x coords={0.01,0.05,0.1,0.2,0.3,0.5,0.6,0.7,0.8,0.9},
xtick=data,
ytick={0,1,2,3,4,5,6,7,8,9,10},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
% Simulated
\addplot[
color=blue,
mark=square,
line width = 1.2pt,
]
coordinates {
(0.01,0.111)(0.05,0.0833)(0.1,0.267)(0.2,0.672)(0.3,1.027)(0.5, 3.2)(0.6, 8.1)(0.7,3.2)(0.8, 0)(0.9,0)
};
\end{axis}
\end{tikzpicture}
\end{document}