0

How can plots, created by matlab2tikz and common tikzpicture-polaraxis be correctly used within the same document?

The example is of the structure packages, matlab2tikz-pic1, matlab2tikz-pic2 and polaraxis-pic.

The matlab2tikz-pictures are just copy paste. They work well (according to its source) with the following codelines used after \begin{document}

\pgfplotsset{compat=1.3,
    every axis legend/.style={
    y tick label style={/pgf/number format/1000 sep=},                  
    x tick label style={/pgf/number format/1000 sep=}}}
    \newlength\figureheight
    \newlength\figurewidth

These lines badly affect the legend in polaraxis-pic (frame and alignment).

Putting these lines in the corresponding figure enviorement (after \begin{ figure}) works just for the first time. The second call creates an "already-defined" error message.

Putting one layer deeper into \begin{tikzpicture} causes a hang up of texmaker.

Any suggestions?

\documentclass[12pt,a4paper]{report}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[ngerman]{babel}                             % Sprache mit Umlauten
\usepackage[{top=3cm,bottom=3cm,left=3cm,right=2cm}]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}                             % Kodierung
\usepackage{mathcomp}
\usepackage{pgfplots}                                   % für matlab2tikz
\usepgfplotslibrary{polar}                              % für Polarplots
\usetikzlibrary{shapes.geometric}                       % für Polarplots
\setlength{\parindent}{0pt}
\newcommand{\xfrac}[2]{%
\mbox{\raisebox{0.6ex}{\ensuremath{\displaystyle #1}}%
{\Large /}%
\raisebox{-0.6ex}{\ensuremath{\displaystyle #2}}}}


\begin{document}
\begin{figure}[h]
\pgfplotsset{compat=1.3,
    every axis legend/.style={
    y tick label style={/pgf/number format/1000 sep=},                  
    x tick label style={/pgf/number format/1000 sep=}}}
    \newlength\figureheight
    \newlength\figurewidth
\begin{center}
\footnotesize
\setlength\figureheight{4cm}
\setlength\figurewidth{8cm} 
% This file was created by matlab2tikz v0.4.2.
\begin{tikzpicture}
\begin{axis}[
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=0,
xmax=5,
xlabel={Tiefe [$\mu$m]},
ymin=0,
ymax=105,
ylabel={Temperaturanstieg [K]}
]
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0 98.3383266017213\\
0.6 75.7037719551423\\
1.4 44.0308586761605\\
1.8 31.8836282059977\\
2.6 15.3339893333299\\
3.9 3.79795619734343\\
5 0.987919017813002\\
};
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.5 80.10874197629\\
1 90.10874197629\\
};
\node[above, right, inner sep=0mm, text=black]
at (axis cs:1,90.10874197629,0) {\scriptsize 30 ns, 0 mm};
\end{axis}
\end{tikzpicture}%
\hspace{2cm}
\end{center}
\caption{Text}
\end{figure}


%%\begin{figure}[h]
%\pgfplotsset{compat=1.3,
%   every axis legend/.style={
%   y tick label style={/pgf/number format/1000 sep=},                  
%   x tick label style={/pgf/number format/1000 sep=}}}
%    \newlength\figureheight
%    \newlength\figurewidth
%\begin{center}
%\footnotesize
%\setlength\figureheight{4cm}
%\setlength\figurewidth{8cm} 
%% This file was created by matlab2tikz v0.4.2.
%\begin{tikzpicture}
%\begin{axis}[
%width=\figurewidth,
%height=\figureheight,
%scale only axis,
%xmin=0,
%xmax=5,
%xlabel={Tiefe [$\mu$m]},
%ymin=0,
%ymax=105,
%ylabel={Temperaturanstieg [K]}
%]
%\addplot [
%color=black,
%solid,
%forget plot
%]
%table[row sep=crcr]{
%0 98.3383266017213\\
%0.6 75.7037719551423\\
%1.4 44.0308586761605\\
%1.8 31.8836282059977\\
%2.6 15.3339893333299\\
%3.9 3.79795619734343\\
%5 0.987919017813002\\
%};
%\addplot [
%color=black,
%solid,
%forget plot
%]
%table[row sep=crcr]{
%0.5 80.10874197629\\
%1 90.10874197629\\
%};
%\node[above, right, inner sep=0mm, text=black]
%at (axis cs:1,90.10874197629,0) {\scriptsize 30 ns, 0 mm};
%\end{axis}
%\end{tikzpicture}%
%\hspace{2cm}
%\end{center}
%\caption{Text1}
%\end{figure}


\begin{figure}[h]
\begin{center}
\footnotesize
\begin{tikzpicture}
\definecolor{lgray}{rgb}{0.7,0.7,0.7}
\definecolor{dgray}{rgb}{0.3,0.3,0.3}
\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep=1pt,
        ellipse,
        anchor=\tick-(180-\pgftransform@angle)
    },
    yticklabel style={
        anchor=90 + \pgftransform@angle
    }
}
\makeatother
\begin{polaraxis}[
  rotate=-90,
  xmin=00,
  xmax=90,
  %xtick={0,30,60,90}
  xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
  xtick={0,15,...,90},
legend style={xshift=3.5cm,yshift=-.2cm}
%legend style={anchor=north west, at={(axis cs:45,4)}}
  ]  
\addplot[red,no markers,smooth] table{
   0 1
   30 2
   60 3
   90 2
    };    
\addlegendentry{Text1}
\addplot[no markers,smooth] table{
   0 2
   30 3
   60 1
   90 1
    };
\addlegendentry{Text2}
\end{polaraxis}
\end{tikzpicture}

\hspace{2cm}
\end{center}
\caption{Text}
\end{figure}

\end{document}
1

Solved by adding the \pgfplotsset-lines only into the first figure environment.

Works but seems not to be good programming. Suggestions are still welcome!

  • 2
    The problem isn't caused by the \pgfplotsset lines, but by the \newlength lines. You can only declare lengths once, so all you have to do is remove the second set of \newlength statements. – Jake Nov 13 '13 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.