8

I'm trying to make an tikz plot from a matlab plot. The problem is that de y label is on the y axis.

Plot image

I used the following code:

\begin{tikzpicture}

\begin{axis}[%
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=0, xmax=320,
xlabel={$\text{Debiet [m}^\text{3}\text{/h]}$},
xmajorgrids,
ymin=0, ymax=9e-006,
ylabel={$\text{d}_{\text{p,100\%}}\text{ [m]}$},
ymajorgrids,
axis lines=left,
title={ },
legend style={nodes=right}]
\addplot [
color=black,
solid
]
coordinates{
...
addlegendentry{$\text{d}_{\text{p,100\%}}\text{ bij ideale aanstroming}$};

\end{axis}
\end{tikzpicture}

.

I tried several things but it still doesn't work. Is there a way I can move the y label to the right or use a common scaling factor on the y-axis.

4
  • I assume you mean "move the y label to the left"?
    – Jake
    Apr 1, 2012 at 11:25
  • possible duplicate of ylabel postion with pgfplots Apr 1, 2012 at 12:45
  • @TorbjørnT.: It's not an exact duplicate, since this question also asks for a way to use a common scaling factor.
    – Jake
    Apr 1, 2012 at 12:54
  • @Jake Sorry, you're right. I missed that last part. Apr 1, 2012 at 12:55

2 Answers 2

13

You can use a common scaling factor by supplying the option scaled y ticks={base 10:6}, which will multiply all y ticks with 10^6 and add the scaling factor 10^-6 to the top of the axis.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
scale only axis,
xmin=0, xmax=320,
xlabel={$\text{Debiet [m}^\text{3}\text{/h]}$},
xmajorgrids,
ymin=0, ymax=9e-006,scaled y ticks={base 10:6},
ylabel={$\text{d}_{\text{p,100\%}}\text{ [m]}$},
ymajorgrids,
axis lines=left,
title={ },
legend style={nodes=right}]
\addplot [
color=black,
solid
] coordinates {(0,7e-6) (320,3e-6)};
\addlegendentry{$\text{d}_{\text{p,100\%}}\text{ bij ideale aanstroming}$};

\end{axis}
\end{tikzpicture}
\end{document}

To avoid the y axis label colliding with the tick labels, you can set the version to use to at least compat=1.3, which will use the special anchor near ticklabel for the axis labels.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
compat=newest,
scale only axis,
xmin=0, xmax=320,
xlabel={$\text{Debiet [m}^\text{3}\text{/h]}$},
xmajorgrids,
ymin=0, ymax=9e-006,
ylabel={$\text{d}_{\text{p,100\%}}\text{ [m]}$},
ymajorgrids,
axis lines=left,
title={ },
legend style={nodes=right}]
\addplot [
color=black,
solid
] coordinates {(0,7e-6) (320,3e-6)};
\addlegendentry{$\text{d}_{\text{p,100\%}}\text{ bij ideale aanstroming}$};

\end{axis}
\end{tikzpicture}
\end{document}
11

Newer versions of pgfplots handle this problem automatically, but you have to call it. You can use \pgfplotsset{compat=newest} to set the compatibility globally, or use compat=newest within the \begin{axis}[ ... ] options.

This option automatically adjusts the spacing of the label to avoid the tick marks. If you want to adjust this further, use ylabel shift={dimension} option (which only works when compat=newest is set.)

3
  • 3
    While this is correct, I would like to note that compat=newest means that the code in question will always and without further notice adapt changes of future versions. It is best-practice to prefer a fixed version, for example compat=1.4 to ensure that your figure will always look the same even in future versions. Apr 1, 2012 at 18:01
  • Good point. I haven't used pgfplots long enough to make old code obsolete, and many times the features I want exist only in the newer revisions, so I generally use newest. But your point is well taken.
    – GregH
    Apr 3, 2012 at 12:29
  • \pgfplotsset{compat=newest} works perfectly! Thank you!
    – Vivian
    Jan 8, 2017 at 20:41

You must log in to answer this question.

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