Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Look at the differences between the following two plots. I would like to have in plot "1" the same distances between the colorbar, axis labels and the ticks labels that I get in plot "2".

How can this be achieved?

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots,pgfplotstable}        % Grafici
\pgfplotsset{/pgf/number format/use comma,compat=newest,%
            width=12cm,%
            height=9cm%
            }

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\pgfplotsset{axis line on top/.style={
 axis on top=false,
 after end axis/.append code={
    \pgfplotsset{axis line style=opaque,
      ticklabel style=opaque,
      tick style=opaque,
      grid=none}
    \pgfplotsdrawaxis}
  }
}
\begin{axis}[/pgf/number format/fixed,
legend pos=outer north east,
grid=major,
xmin=0, xmax=0.2,
ymin=0, ymax=0.6,
point meta min={0},
point meta max={0.2},
yticklabel shift=2pt,
xticklabel shift=2pt,
legend pos=north west,
minor tick num=4,
axis line on top,
xticklabel style={text height=1.5ex},
xtick={0,0.05,...,0.3},
minor xtick={0,0.01,...,0.2},
extra x ticks={0,0.05,...,0.3},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
extra y ticks={0,0.1,...,0.7},
extra y tick style={
    yticklabel pos=right
},
tick style={thin,black},
xlabel=\large $m$,
ylabel=\large $\Delta l$,
colorbar horizontal,
colorbar style={
    /pgf/number format/fixed,
    xticklabel shift=2pt,
    xtick={0,0.05,...,0.3},
    xticklabel style={text height=1.5ex}
},
colormap={new}{color(0cm)=(violet);color(1cm)=(blue);color(2cm)=(cyan);color(3cm)=(green);color(4cm)=(yellow);color(5cm)=(orange);color(6cm)=(red)},
legend cell align=left]
\end{axis}
\end{tikzpicture}
\end{figure}


\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
yticklabel shift=2pt,
xticklabel shift=2pt,
xmin=-6, xmax=6,
ymin=0, ymax=6,
point meta min={-6},
point meta max={6},
xlabel=\large $m$,
ylabel=\large $\Delta l$,
colorbar horizontal,
colorbar style={
    /pgf/number format/fixed,
    xticklabel shift=2pt,
    xtick={-6,-4,...,6},
    xticklabel style={text height=1.5ex}
},
colormap={new}{color(0cm)=(violet);color(1cm)=(blue);color(2cm)=(cyan);color(3cm)=(green);color(4cm)=(yellow);color(5cm)=(orange);color(6cm)=(red)}
]
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
share|improve this question
    
does not work... –  FormlessCloud Jun 5 '12 at 18:22
    
If i remove the initial settings i don't see any difference, i see only a smaller plot but the distance is the same... –  FormlessCloud Jun 5 '12 at 18:31
    
I see that too now. It is indeed weird. –  percusse Jun 5 '12 at 20:58
    
how i can fix that behaviour? maybe Jake could have the answer... –  FormlessCloud Jun 5 '12 at 21:01
    
This seems to be caused by the axis line on top style and the extra x ticks. Do you actually need the axis line on top for this plot? –  Jake Jun 6 '12 at 8:47

1 Answer 1

up vote 2 down vote accepted

The problem with the grey axis lines appears because the major grid lines coincide with the axis lines. Instead of axis lines on top, you can use axis line style={draw=none}, after end axis/.append code={\draw (rel axis cs:0,0) rectangle (rel axis cs:1,1);},. There's still a small offset of the x label that comes from the extra x ticks (even though it shouldn't).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%THANKS JAKE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots,pgfplotstable}        % Grafici
\pgfplotsset{/pgf/number format/use comma,compat=newest,%
            width=12cm,%
            height=9cm%
            }

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[/pgf/number format/fixed,
legend pos=outer north east,
grid=major,
xmin=0, xmax=0.2,
ymin=0, ymax=0.6,
point meta min={0},
point meta max={0.2},
yticklabel shift=2pt,
xticklabel shift=2pt,
legend pos=north west,
%minor tick num=4,
xticklabel style={text height=1.5ex},
xtick={0,0.05,...,0.3},
%minor xtick={0,0.01,...,0.2},
%minor ytick={0,0.02,...,0.6},
extra x ticks={0,0.05,...,0.3},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
extra y ticks={0,0.1,...,0.7},
extra y tick style={
    yticklabel pos=right
},
tick style={thin,black},
xlabel=\large $m$,
ylabel=\large $\Delta l$,
colorbar horizontal,
colorbar style={
    /pgf/number format/fixed,
    xtick={0,0.05,...,0.3},
    xticklabel shift=2pt,
    xticklabel style={text height=1.5ex}
},
axis line style={draw=none}, after end axis/.append code={\draw (rel axis cs:0,0) rectangle (rel axis cs:1,1);},
colormap={new}{color(0cm)=(violet);color(1cm)=(blue);color(2cm)=(cyan);color(3cm)=(green);color(4cm)=(yellow);color(5cm)=(orange);color(6cm)=(red)},
legend cell align=left]
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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