1

I am trying to include a matlab graphic in my LaTeX document, using the matlab2tikz script from File Exchange. The problem is the following: The graphic, that I am trying to include, shows two plots with a common x-axis, but different y-axes. In my .tikz file, this gets mixed up.

Here is the .tikz file: https://www.dropbox.com/s/pylakdx2mqrn17z/example1?dl=0

I hope you can help,

thx in advance !!

  • 1
    Instead of the Dropbox-link, can you add the code directly to your question? (After pasting, select it and click the button marked {} for syntax highlighting.) – Torbjørn T. Feb 12 '17 at 11:28
1

This is the behavior of older versions of pgfplots, and also newer versions behave like this when running in backward compatibility mode.

Take a look at your log file. There you will find something like

Package pgfplots Warning: running in backwards compatibility mode (unsuitable t
ick labels; missing features). Consider writing \pgfplotsset{compat=1.14} into 
your preamble.

Well, add \pgfplotsset{compat=1.14} (or whatever the log file tells you) after the line \usepackage{pgfplots}.

This is what I get after adding the line:

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{amsmath}
% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{1.00000,0.00000,1.00000}%
%
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=4.602in,
height=3.82in,
at={(0.772in,0.516in)},
scale only axis,
xmin=-30,
xmax=5,
xlabel style={font=\color{white!15!black}},
xlabel={$\text{P}_{\text{in}}\text{ [dBm]}$},
every outer y axis line/.append style={mycolor1},
every y tick label/.append style={font=\color{mycolor1}},
every y tick/.append style={mycolor1},
ymin=36,
ymax=52,
ylabel style={font=\color{mycolor1}},
ylabel={$\text{P}_{\text{out}}\text{ [dBm]}$},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids,
legend style={at={(0.03,0.97)}, anchor=north west, legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1]
  table[row sep=crcr]{%
-25.21  36.83\\
-20.22  41.62\\
-18.21  43.51\\
-17.21  44.44\\
-16.21  45.36\\
-15.25  46.21\\
-14.26  47.05\\
-13.27  47.86\\
-12.26  48.62\\
-11.76  48.98\\
-11.26  49.33\\
-10.27  49.94\\
-9.77   50.22\\
-9.27   50.47\\
-8.77   50.71\\
-7.76   51.1\\
-7.27   51.25\\
-6.76   51.38\\
-6.26   51.47\\
-5.76   51.53\\
-5.26   51.55\\
-4.76   51.53\\
-4.27   51.46\\
-3.77   51.36\\
-3.28   51.2\\
-2.77   51\\
-2.28   50.75\\
-1.78   50.46\\
-1.27   50.1\\
-0.780000000000001  49.71\\
-0.280000000000001  49.27\\
0.219999999999999   48.79\\
0.719999999999999   48.25\\
};
\addlegendentry{AM/AM}

\end{axis}

\begin{axis}[%
width=4.602in,
height=3.82in,
at={(0.772in,0.516in)},
scale only axis,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmin=-30,
xmax=5,
xtick={-30,-25,-20,-15,-10,-5,0,5},
xticklabels={\empty},
every outer y axis line/.append style={blue},
every y tick label/.append style={font=\color{blue}},
every y tick/.append style={blue},
ymin=0,
ymax=40,
ylabel style={font=\color{blue}},
ylabel={$\text{Phi}_{\text{out}}\text{ [deg]}$},
axis x line*=top,
axis y line*=right
]
\addplot [color=blue, forget plot]
  table[row sep=crcr]{%
-25.21  0\\
-24.23  0.119999999999997\\
-23.24  0.170000000000002\\
-22.23  0.25\\
-21.22  0.310000000000002\\
-20.22  0.439999999999998\\
-19.2   0.619999999999997\\
-18.21  0.93\\
-17.21  1.35\\
-16.21  1.97\\
-15.25  2.69\\
-14.26  3.7\\
-13.27  4.97\\
-12.26  6.5\\
-11.76  7.37\\
-10.76  9.26\\
-9.27   12.34\\
-8.77   13.42\\
-8.26   14.59\\
-6.76   18.15\\
-6.26   19.51\\
-5.26   22.54\\
-4.76   24.05\\
-4.27   25.62\\
-3.28   28.66\\
-2.77   30.13\\
-2.28   31.5\\
-1.78   32.81\\
-1.27   34.09\\
-0.280000000000001  36.64\\
0.219999999999999   37.86\\
0.719999999999999   39.02\\
};
\end{axis}
\end{tikzpicture}%
\end{document}
  • thx gernot, it works! - Just two remarks: The legend still only shows one of the plots, why is the other missing? And do you know a why of sizing the image? In LaTeX I am using \input{figure} to include the figure. So I would like to scale the figure in Matlab. – user123551 Feb 12 '17 at 12:58
  • I have just added these code-lines to Matlab: % LaTeX set up height=10; width=10; set( gcf, 'Units', 'centimeters' ) set( gcf, 'Position', [ 0 0 width height ] ) set( gcf, 'PaperUnits', 'centimeters' ) set( gcf, 'PaperSize', [ width height ] ) set( gcf, 'PaperPositionMode', 'Manual' ) set( gcf, 'PaperPosition', [ 0 0 width height ] ) box off .. the figure is scaled now, but the blue line goes a little below the x-axis ?! – user123551 Feb 12 '17 at 13:30
  • @Luk I don't use Matlab, but the second axis is missing any mentioning of a legend. Maybe some settings in Matlab are missing to instruct Matlab to add a legend also for the second plot? Regarding scaling, I only know the options for scaling in LaTeX. Maybe ask a new question with a description of your current settings; probably other people here are experienced Matlab users. – gernot Feb 12 '17 at 13:32

Your Answer

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