3

I am trying to extract some plots from Matlab for XeLaTex using Matlab2Tikz. All goes well, except the plot with the loglog scale (I included a figure, see below). The left bottom plot shows a loglog scale with 10-base tick labels on the y-axis and a logarithmic scale on the x-axis but without 10-base. When performing the matlab2tikz command, I get 10-base x tick labels which I clearly don't need. Instead, I would like to have it the way Matlab plots it.

I haven't found a similar problem here on stackexchange so I thought I'd ask it myself.

Thank you very much in advance!

EDIT: Here is the code:

\begin{axis}[%
width=\fwidth,
height=\fheight,
scale only axis,
separate axis lines,
every outer x axis line/.append style={white!15!black},
every x tick label/.append style={font=\color{white!15!black}},
xmode=log,
xmin=1,
xmax=8,
xminorticks=true,
every outer y axis line/.append style={white!15!black},
every y tick label/.append style={font=\color{white!15!black}},
ymode=log,
ymin=0.0001,
ymax=1,
yminorticks=true,
ylabel={E(K)},
at=(plot3.below south west),
anchor=above north west
]
\addplot [color=red,solid,mark=o,mark options={solid},forget plot]
  table[row sep=crcr]{1 0.0711717716815872\\
2   0.0115273918542792\\
3   0.00554837295582636\\
4   0.00390493819982627\\
5   0.00257462558614867\\
6   0.000676170571559625\\
7   0.000211268404410399\\
8   0.000179355383693616\\
};
\end{axis}

Bottom plot left is how i Like it to be, bottom plot right is how i get it in LaTeX

4
  • Please provide the code. Sep 22, 2015 at 15:50
  • I am sorry, I am new to this. I have edited it :-)!
    – Jos
    Sep 22, 2015 at 15:59
  • No problem. However, is that the resulting LaTeX code? Sep 22, 2015 at 16:00
  • See the answer provided. The same option applies in your concrete example. Sep 22, 2015 at 16:11

2 Answers 2

2

For the y-axis, you can use ytickend to provide a list of the desired tick locations (it admits the ... shortcut). In your case, you can use

ytickten={-4,-2,0}

For the x-axis, you need to change the tick representation using

  xtick=data,
  xticklabel=\pgfmathparse{e^\tick}\pgfmathprintnumber{\pgfmathresult}

A complete example:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{loglogaxis}[%
  scale only axis,
  separate axis lines,
  every outer x axis line/.append style={white!15!black},
  xmode=log,
  xmin=1,
  xmax=8,
  every outer y axis line/.append style={white!15!black},
  every y tick label/.append style={font=\color{white!15!black}},
  ymode=log,
  ymin=0.0001,
  ymax=1,
  ylabel={E(K)},
  anchor=above north west,
  ytickten={-4,-2,0},
  xtick=data,
  xticklabel=\pgfmathparse{e^\tick}\pgfmathprintnumber{\pgfmathresult}
]
\addplot [color=red,solid,mark=o,mark options={solid},forget plot]
  table[row sep=crcr]{
1 0.0711717716815872\\
2   0.0115273918542792\\
3   0.00554837295582636\\
4   0.00390493819982627\\
5   0.00257462558614867\\
6   0.000676170571559625\\
7   0.000211268404410399\\
8   0.000179355383693616\\
};
\end{loglogaxis}
\end{tikzpicture}

\end{document}

enter image description here

3
  • This, indeed changes the tick labels of either axis. But now the follow up question: I would like to drop the 10 basis notation on the x-axis (y-axis is fine the way it is). I tried: xtickten={e^{1},e^{2}} (And variations of this). As it is its reverse, hoping that I would get an x-axis similar to the Matlab plot (bottom) shown in my openings post. Unfortunately, this does not work.
    – Jos
    Sep 23, 2015 at 13:49
  • @Jos Please see my updated answer. Sep 23, 2015 at 14:28
  • This works like a champ! Thank you so much for your help!
    – Jos
    Sep 23, 2015 at 15:02
0

For me, the existing answer didn't work correctly, because some values were still represented differently, e. g. 20 was rendered as 19.99.

Now, I finally managed to solve the problem by inserting the line log ticks with fixed point into the \begin{axis}[...] options in the .tikz file:

\begin{axis}[%
...,
log ticks with fixed point
]
...

With matlab2tikz, this can be achieved using the following code:

matlab2tikz(tikzFileName, ...
   'extraaxisoptions', 'log ticks with fixed point'... % this line is new
);

You must log in to answer this question.

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