10

I've done a plot with pgfplots enter image description here

with this code

\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}

Now, i want to add a text box above the legend to write an equation, do you know the way to do this?

thank you

3 Answers 3

12

You have 3 possibilities: absolute and two times relative to the legend.

\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}

enter image description here

6

Like this?

enter image description here

\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}

Since I haven't your data tables, I draw simple function with two coordinates.

3
  • ok thank you it works. But if i wat to write on multiples rows, it is possible within the node? I mean, if i want to write more than one equation in the data text, how can i do? Commented Feb 25, 2016 at 18:44
  • @PaoloOrsatti, you can do this on two ways: (i) add option align=... to the node and manulay break node text into more lines, or (ii) also define text width=.. of node which will automatically break lines.
    – Zarko
    Commented Feb 25, 2016 at 18:49
  • i use the first option with align=. It works perfectly, thank you very much! Commented Feb 25, 2016 at 20:36
3

I was too slow... but I edited a bit in order to get a nicer scaling of your plot:

% 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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .