我不太熟悉 tikz 图。图看起来确实应该如此,但我想更改最后一个位置值300到n在情节中。这可能吗?
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
% for graphs
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc}
\def\layersep{2.5cm}
\usepackage{pgfplots}
\pgfplotsset{compat=1.4}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=No. of Neihbours,
ylabel=MAE
]
\addplot plot coordinates {
(1, 0.753804)
(10, 0.759822)
(25, 0.745213)
(50, 0.741495)
(75, 0.743365)
(100, 0.746219)
(175, 0.755337)
(200, 0.758157)
(300, 0.825300)
};
\legend{$fullcos$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
一种可能性是使用xticklabels={<list of values>}
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=No. of Neighbours,
ylabel=RSME,
xticklabels={0,0,50,100,150,200,250,n},
]
\addplot plot coordinates {
(1, 1.040923)
(10, 1.015503)
(25, 0.947140)
(50, 0.923818)
(75, 0.922332)
(100, 0.925733)
(175, 0.941590)
(200, 0.946928)
(300, 1.064557)
};
\legend{$d=2$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
\end{axis}
\end{tikzpicture}
\end{document}
如果 x 标签列表太长,上述解决方案可能会很麻烦;这里是另一种方法,只允许更改最后一个标签,而不修改之前的值:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=No. of Neighbours,
ylabel=RSME,
every x tick label/.append style={alias=ultick},
extra description/.append code={
\fill [white] (ultick.north west) ++(0pt,-2\pgflinewidth) rectangle (ultick.south east);
\node [anchor=south] at (ultick.south) {n};} ]
\addplot plot coordinates {
(1, 1.040923)
(10, 1.015503)
(25, 0.947140)
(50, 0.923818)
(75, 0.922332)
(100, 0.925733)
(175, 0.941590)
(200, 0.946928)
(300, 1.064557)
};
\legend{$d=2$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
\end{axis}
\end{tikzpicture}
\end{document}