使用代码
\begin{tikzpicture}[scale=0.8]
\begin{axis}[colormap/blackwhite,legend style ={ at={(1.03,1)},
anchor=north west, draw=black,
fill=white,align=left},
cycle list name=black white,
smooth]
\addplot coordinates{(1,0.895975056689342) (2,0.88858024691358) (3,0.845842956120092) (4,0.939493433395872) (5,0.876114081996435) (6,0.855309218203034) (7,0.85309649543927) (8,0.894003868471954) (9,0.857021996615905) (10,0.842038753159225) (11,0.89045719545873) (12,0.839759462327556) (13,0.794553464156988) (14,0.800123762376238)};
\end{axis}
\end{tikzpicture}
我可以绘制一条实验曲线。我想用对替换 x 值,例如用 (5,95) 替换 1,用 (6,94) 替换 2,等等。像这样:
答案1
简单的尝试没有成功,但你可以通过手动指定和symbolic x coords
来实现。 可以采用数字列表,例如给出从 1 到 5 的整数,或者关键字(即),它将在xtick
xticklabels
xtick
{1,...,5}
data
xtick=data
第一的 \addplot
。
xticklabels
采用逗号分隔的文本列表作为刻度标签。在您的例子中,您需要将每个刻度标签包装在 中{}
,因为其中有一个逗号。请参阅下面的完整示例。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap/blackwhite,
legend style = {
at={(1.03,1)},
anchor=north west,
align=left
},
cycle list name=black white,
smooth,
xtick={1,5,9},
xticklabels={{(1,3.13)},{(2,42)},{(3,1.618)}}
]
\addplot coordinates{(1,0.895975056689342) (2,0.88858024691358) (3,0.845842956120092) (4,0.939493433395872) (5,0.876114081996435) (6,0.855309218203034) (7,0.85309649543927) (8,0.894003868471954) (9,0.857021996615905) (10,0.842038753159225) (11,0.89045719545873) (12,0.839759462327556) (13,0.794553464156988) (14,0.800123762376238)};
\end{axis}
\end{tikzpicture}
\end{document}