2

enter image description hereI just included matlab figures using matlab2tikz. I have annotations in my figures. These annotations are outside the plot area to prevent overlap with the data. But now I also want the annotations outside the plot in my latex file. If possible i want to implement it into the tikz file(not in the latex file).

I tried the following using `minipage

http://tex.stackexchange.com/questions/99224/putting-text-at-the-side-of-a-tikzpicture

setting clip=false (Didn't do anything)

Minipage worked but when i resized my plot in latex the annotations didn't scale and are now halve inside the plot.

using node[text width=6cm, anchor=west, right] at (5,0)
    {In this diagram, what can you say about $\angle F$, $\angle B$ and $\angle E$?};

from the same link (Didn't work)

I'm not very experienced with Tikz. I just tried some different methods, but none seems to work.

here is the tikz file:

    \begin{tikzpicture}
\begin{axis}[%
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=30,
xmax=330,
xlabel={$\text{T}_{\text{surr}}\text{ (K)}$},
ymin=0,
ymax=120,
ylabel={$\text{Q}_{\text{Cooling}}\text{ (W)}$},
axis background/.style={fill=white},
title style={font=\bfseries},
title={Cooling power for surrounding temperatures},
axis x line*=bottom,
axis y line*=left
]
\addplot [color=mycolor1,solid,forget plot]
  table[row sep=crcr]{%
30  6.97463548006898\\
60  7.00516177264937\\
90  7.36872538108224\\
120 8.92825821383692\\
150 12.7097699247381\\
180 19.3898073983116\\
210 29.107506124354\\
240 42.0222333872511\\
270 58.3725938451868\\
300 78.4696582472676\\
330 102.691450312509\\
};
\end{axis}

\begin{axis}[%
width=1.227\figurewidth,
height=1.227\figureheight,
at={(-0.16\figurewidth,-0.135\figureheight)},
scale only axis,
xmin=0,
xmax=1,
ymin=0,
ymax=1,
hide axis,
axis x line*=bottom,
axis y line*=left
]
**\node[below right, align=left, text=black, draw=black]
at (rel axis cs:0.75,0.15) {G10 \\$\text{ }\epsilon\text{ = 1 }$\\ F = 1 \\$\text{ T}_{\text{start}}\text{ = 330 }$\\$\text{ T}_{\text{end}}\text{ = 30 }$\\$\text{ dT}_{\text{max}}\text{ = 1 }$\\ N = 100};**
\end{axis}
\end{tikzpicture}%

1 Answers1

1

Your code works if you add clip=false to the second axis environment, containing the node with the annotation. Having done that you can just move it to the position of your choice, by changing the coordinates for the \node.

That said, the second axis environment is not really necessary here, you might as well add it inside the first axis environment, or right outside it, placing it relative to the axis.

In the code below both options are demonstrated. Note that I've added name=MyAxis to the axis options, and the node is placed at MyAxis.north east. I don't know what G10 is, but it seemed like it was a heading of sorts, hence the bold text. Of course, remove that \textbf if you don't want it. I also set the list of values using aligned.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots,amsmath}
\newlength{\figurewidth}
\setlength{\figurewidth}{10cm}
\newlength{\figureheight}
\setlength{\figureheight}{5cm}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
name=MyAxis,
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=30,
xmax=330,
xlabel={${T}_{\text{surr}}\text{ (K)}$},
ymin=0,
ymax=120,
ylabel={$\text{Q}_{\text{Cooling}}\text{ (W)}$},
axis background/.style={fill=white},
title style={font=\bfseries},
title={Cooling power for surrounding temperatures},
axis x line*=bottom,
axis y line*=left,
%clip=false %uncomment this if you want the annotation outside the axis
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{%
30  6.97463548006898\\
60  7.00516177264937\\
90  7.36872538108224\\
120 8.92825821383692\\
150 12.7097699247381\\
180 19.3898073983116\\
210 29.107506124354\\
240 42.0222333872511\\
270 58.3725938451868\\
300 78.4696582472676\\
330 102.691450312509\\
};

\node[below right, align=center, text=black]
at (rel axis cs:0.1,0.9) {\textbf{G10} \\
$\begin{aligned} 
\epsilon &= 1\\
 F &= 1 \\
T_{\text{start}} &= 330 \\
T_{\text{end}} &= 30\\
\mathrm{d}T_{\text{max}}&= 1\\
 N &= 100
\end{aligned}$};

\end{axis}

\node[below right, align=center, text=black]
at (MyAxis.north east) {%
\textbf{G10} \\
$\begin{aligned} 
\epsilon &= 1\\
 F &= 1 \\
T_{\text{start}} &= 330 \\
T_{\text{end}} &= 30\\
\mathrm{d}T_{\text{max}}&= 1\\
 N &= 100
\end{aligned}$};
\end{tikzpicture}%
\end{document}
Torbjørn T.
  • 206,688
  • Torbjorn, Thanks a lot for explaining and also showing that i need only 1 axis. The second axes is probably because i added the annotations inside matlab. Only one question remains. I get a error message (see image in post) when i dont remove everything above \begin{tikzpicture} and below \end{tikzpicture}. Is the rest to save at as a tex. file and externalise the image to prevent exceeding the Tex capacity? This happens if i add a different picture. But I have'n't figure out how to load .tex file if i save it like that, because \begin{figure}[htb] \input{mysphere.tex} \end{figure} – fahrenheiz Nov 26 '15 at 08:55
  • @fahrenheiz I don't fully understand. To use it as \begin{figure}\input{file.tex}\end{figure}, file.tex cannot contain a \documentclass, the preamble and document environment, it should only contain the tikzpicture environment. – Torbjørn T. Nov 26 '15 at 09:34
  • The script is an external tikz or tex file. The begin figure,input is to include into my main tex file which is a report with the different graphs. But this doesn't seem to work for most images because the Tex capapacity is exceeded. – fahrenheiz Nov 26 '15 at 09:49
  • I get now that the \documentclass is only for the main document, but looking around this capacity error i see that most people don't use matlab2tikz but only use the data from matlab and do the plotting in a different way. – fahrenheiz Nov 26 '15 at 09:52
  • @fahrenheiz That can happen with large datafiles, but is unrelated to the error you show in the image. Externalisation doesn't help? Can you compile with lualatex instead of pdflatex? – Torbjørn T. Nov 26 '15 at 09:53
  • @fahrenheiz Either way, the capacity problem is completely unrelated to the question I answered, so it would be better if you asked a new question, assuming you cannot find an existing one with a useful solution. – Torbjørn T. Nov 26 '15 at 09:54
  • Yea sorry, you answered my question the error above is resolved. Really thank you for that. It is just that I still have no way of making neat matlab figures into latex. – fahrenheiz Nov 26 '15 at 10:06
  • @fahrenheiz I guess matlab2tikz does an OK job in a lot of cases. You could of course just export the data from Matlab as .csv files and learn to use pgfplots (see the manual for all the details, and https://www.tug.org/TUGboat/tb31-1/tb97wright-pgfplots.pdf for a quick intro). That wont help with the capacity problem of course, but it does give you more flexibility if you do things on your own. As mentioned, compiling with lualatex instead of pdflatex can help some, as can using the external library, or downsampling the data. – Torbjørn T. Nov 26 '15 at 10:15