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.

Why in this plot the axis are all staggered ?

\documentclass[12pt,%                      % corpo del font principale
                   a4paper,%                   % carta A4
    %               draft,%                     % evidenzia le righe Overfull hbox
                   twoside,%
    %               oneside,%
    %               openright,%                % fronte-retro
                   openany%                    % solo fronte
                   ]{book}


    \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=80, xmax=100,
    ymin=0, ymax=100,
    point meta min={80},
    point meta max={100},
    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={80,0.5,...,100},
    minor xtick={80,0.05,...,100},
    extra x ticks={80,0.5,...,100},
    extra x tick style={
        xticklabel pos=right,
        xticklabel style={text depth=0pt}
    },
    extra y ticks={0,20,...,100},
    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={80,0.5,...,100},
        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)},
    after end axis/.append code={
        \draw ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis cs:0,0});
    },
    legend cell align=left]
    \end{axis}
    \end{tikzpicture}
    \caption{Grafico dei dati.}
    \label{fig:Grafico_ottica}
    \end{figure}
    \end{document}
share|improve this question
    
I have realized after I was posted and I was correcting ! :S –  FormlessCloud Jun 4 '12 at 20:43
1  
Excuse my impatience then :) But the \slope and \intercept is still undefined. –  percusse Jun 4 '12 at 20:43
    
now it's ok :D ! forgive me you ! –  FormlessCloud Jun 4 '12 at 20:53

1 Answer 1

up vote 4 down vote accepted

This happens because you're trying to draw a line at x=0, but that x value is not actually on your plot. Two ways you can rectify this:

  • Change after end axis/.code to before end axis/.code. That way, the line will be clipped from your plot and not influence the bounding box.
  • Remove the whole after end axis/.code={...}.

\documentclass[12pt,%                      % corpo del font principale
                   a4paper,%                   % carta A4
    %               draft,%                     % evidenzia le righe Overfull hbox
                   twoside,%
    %               oneside,%
    %               openright,%                % fronte-retro
                   openany%                    % solo fronte
                   ]{book}
\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=80, xmax=100,
ymin=0, ymax=100,
point meta min={80},
point meta max={100},
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={80,0.5,...,100},
minor xtick={80,0.05,...,100},
extra x ticks={80,0.5,...,100},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
extra y ticks={0,20,...,100},
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={80,0.5,...,100},
    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)},
before end axis/.append code={
    \draw ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis cs:0,0});
},
legend cell align=left]
\end{axis}
\end{tikzpicture}
\caption{Grafico dei dati.}
\label{fig:Grafico_ottica}
\end{figure}
\end{document}
share|improve this answer
    
don't work any solution :S –  FormlessCloud Jun 4 '12 at 21:12
    
@FormlessCloud: I've added the code altered according to the first suggestion. –  Jake Jun 4 '12 at 21:13
    
but you have not changed after to before in this code... after end axis/.append code={ \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque, grid=none} \pgfplotsdrawaxis} } –  FormlessCloud Jun 4 '12 at 21:18
    
@FormlessCloud: Sorry, pasted the wrong code. –  Jake Jun 4 '12 at 21:24
    
i have understand is the "before" in the lower part of the code :D –  FormlessCloud Jun 4 '12 at 21:28

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.