我有这个代码:
\begin{figure}[!ht]
\resizebox{\textwidth}{!}{
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=90,axis y line*=left,ymin=8.62,ymax=8.69, xlabel=
{Tempo [ore]}, ylabel={Pressione [bar]},title={$P_{media}$ VS
$T_{media}$},legend style={at={(1,1)},anchor=south east}]
\addplot[thick,black] table[x=tempo,y=P_mean]
{capitolo4/grafici/t_meanVSp_mean2.txt};
\addlegendentry={Pressione}
\end{axis}
\begin{axis}[xmin=0, xmax=90,axis y line*=right,ymin=20.5,ymax=23.0, ylabel=
{Temperatura [°C]}]
\addplot[dashed,black] table[x=tempo,y=T_mean]
{capitolo4/grafici/t_meanVSp_mean2.txt};
\addlegendentry={Temperatura}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=90,ymin=8.55,ymax=8.75,xlabel={Tempo [ore]},
ylabel={Pressione [bar]},title={$P_{sperimentale}$ VS $P_{ideale}$ },legend
style={at={(1,1)},anchor=north east}]
\addplot[only marks,mark=o] table[x=tempo,y=p_sp]
{capitolo4/grafici/t_meanVSp_mean3.txt};
\addplot[thick,black] table[x=tempo,y=p_id]
{capitolo4/grafici/t_meanVSp_mean3.txt};
\legend={Psperimentale,Pideale}
\end{axis}
\end{tikzpicture}
}
因此它不会在图中写下标记的名称,并且图例的位置也不在它应该在的位置(我设置为东南,但它打印在图中东北)。
答案1
您确实应该在问题中添加一个可编译的 MWE。我刚刚删除了所有依赖于外部包的内容,现在我有这个:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=90,axis y line*=left,ymin=8.62,ymax=8.69, xlabel=
{Tempo [ore]}, ylabel={Pressione [bar]},title={$P_{media}$ VS
$T_{media}$},legend pos = north east]
\addplot[thick,black] {8.63};
\legend{Pressione}
\end{axis}
\begin{axis}[xmin=0, xmax=90,axis y line*=right,ymin=20.5,ymax=23.0, ylabel=
{Temperatura [°C]} ,legend style={at={(1,.8)},anchor=north east} ]
\addplot[dashed,black] {x};
\legend{Temperatura}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=90,ymin=8.55,ymax=8.75,xlabel={Tempo [ore]},
ylabel={Pressione [bar]},title={$P_{sperimentale}$ VS $P_{ideale}$ },legend
style={at={(1,1)},anchor=north east}]
\addplot[only marks,mark=o] {x};
\addplot[thick,black] {x};
\legend{Psperimentale,Pideale}
\end{axis}
\end{tikzpicture}
\end{document}
编译结果为:
主要问题在于奇怪的用法\addlegendentry=
——我认为您混淆了命令和按键。
您可以在手册第 4.9.4 节(图例)及其后的第 234 页找到有关图例的信息版本 1.13。