如何使用 pgfplots 在图中添加文本框?

如何使用 pgfplots 在图中添加文本框?

我用 pgfplots 画了一个图 在此处输入图片描述

使用此代码

\begin{figure}[!ht]
\resizebox{\textwidth}{!}{
\begin{tikzpicture}
\begin{semilogyaxis}[scale only axis, xmin=-20, xmax=200,      ymin=0.01, 
ymax=20, xlabel={Temperatura [°C]}, ylabel={Pressione  [bar]},
,legend style={draw=none,at={(.99,.1)},anchor=south east},log ticks with  
fixed point ]
\addplot[only marks, mark=*] table[x=t_mean,y=p_mean] 
{capitolo6/grafici_6/tensione_vapore.txt};
\addplot[thick,black,mark=none] table[x=t_fit,y=p_fit]
{capitolo6/grafici_6/tensione_vaporeFIT.txt};
\legend{Valori misurati,Curva di riferimento}
\end{semilogyaxis}
\end{tikzpicture}
}
\end{figure}

现在,我想在图例上方添加一个文本框来写一个方程式,你知道该怎么做吗?

谢谢

答案1

您有 3 种可能性:绝对的和两次相对于图例的。

\documentclass[border=3mm]{standalone}
\usepackage{graphicx,lipsum,pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{tikzpicture}
\begin{semilogyaxis}[scale only axis, xmin=-20,xmax=200,ymin=0.01,ymax=20, xlabel={Temperatura [°C]}, ylabel={Pressione  [bar]},
legend style={draw=none,at={(.99,.1)},anchor=south east},log ticks with  fixed point,
% relative with legend style
legend style={draw=none,fill=none,name=legend,label=above : {relative with legend style}},
]
    \addplot[only marks, mark=*, domain=0:200] {exp(.01*x)};
    \addplot[thick,black,mark=none, domain=0:200] {exp(.01*x)};
    \legend{Valori misurati,Curva di riferimento}

    % absolute in pgfplots coordinates
    \node[] at (axis cs: 150,.9) {absolute in pgfplots coordinates};
\end{semilogyaxis}

% relative to legend node
\node[anchor=east] at (legend.west) {relative to legend node};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

像这样?

在此处输入图片描述

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}
    \begin{tikzpicture}
\begin{semilogyaxis}[
scale only axis, 
xmin=-20, xmax=200,      
ymin=0.01,ymax=20, 
xlabel={Temperatura [°C]}, 
ylabel={Pressione  [bar]},
legend style={draw=none,at={(.99,.1)},anchor=south east},
log ticks with fixed point 
                    ]
\addplot[only marks, mark=*] coordinates {(-20,0.01) (200,20)};

\addplot[thick,black,mark=none] coordinates {(-20,0.01) (200,20)};

\legend{Valori misurati,Curva di riferimento};
\node[above,red] at (150,0.08) {$\log_{10} 10=1$};
\end{semilogyaxis}
    \end{tikzpicture}
\end{document}

由于我没有您的数据表,所以我用两个坐标绘制了简单的函数。

答案3

我太慢了...但我进行了一些编辑以便更好地缩放你的情节:

% arara: pdflatex

\documentclass{article}
\usepackage[italian]{babel}
\usepackage{blindtext}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepackage{siunitx}

\newsavebox{\measuredSize}
\newcommand{\resizeToWidth}[2]{%
    \pgfmathsetmacro{\pgfplotswidth}{#2}%
    \begin{lrbox}{\measuredSize}#1\end{lrbox}%
    \pgfmathsetmacro{\pgfplotswidth}{2*\pgfplotswidth-\wd\measuredSize}%
    #1%
}

\begin{document}
\blindtext
\newcommand{\inputPlot}{%
    \begin{tikzpicture}
    \begin{semilogyaxis}[%
    ,width=\pgfplotswidth,height=7cm
    ,xmin=-20,xmax=200
    ,ymin=0.01,ymax=20
    ,xlabel={Temperatura in \si{\celsius}}
    ,ylabel={Pressione in \si{\bar}}
    ,legend style={%
        ,draw=none
        ,at={(.99,.1)}
        ,anchor=south east
    }
    ,log ticks with fixed point
    ]
    \addplot[only marks, mark=*] {x};
    \addplot[thick,black,mark=none] {x^2};
    \legend{Valori misurati,Curva di riferimento}
    \node at (axis cs:150,.15) {Hello World};
    \end{semilogyaxis}
    \end{tikzpicture}%
}   
\begin{figure}[!ht]
\resizeToWidth{\inputPlot}{\textwidth}
\end{figure}
\blindtext
\end{document}

在此处输入图片描述

相关内容