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.

How i can synchronize the filling of the bars with the color of the color bar to the right? they are a little shifted...

enter image description here

\documentclass[border=0.5mm,12pt]{standalone}

\usepackage{pgfplots,pgfplotstable}        % Grafici

\pgfplotsset{%
            mesh line legend/.style={legend image code/.code=\meshlinelegend#1},%
            /pgf/number format/use comma,%
            compat=newest,%
%            height=9cm,%
            width=12cm%
}
\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}
  }
}
\pgfdeclareverticalshading{stefan}{50bp}{
color(0.00000000000000bp)=(violet);
color(8.33333333333333bp)=(blue);
color(16.66666666666670bp)=(cyan);
color(25.00000000000000bp)=(green);
color(33.33333333333330bp)=(yellow);
color(41.66666666666670bp)=(orange);
color(50.00000000000000bp)=(red)
}
\begin{axis}[%
xtick=data,
/pgf/number format/fixed,
legend pos=outer north east,
ymajorgrids=true,
%ybar,
%x tick label as interval,
enlarge x limits=false,
x filter/.code=\pgfmathparse{#1-0.5},
%xmin=0, xmax=7,
ymin=0, ymax=14,
point meta min={0},
point meta max={14},
yticklabel shift=2pt,
xticklabel shift=2pt,
minor ytick={0,0.4,...,14},
xticklabel style={text height=1.5ex},
xtick={0,1,...,7},
extra x ticks={0,1,...,7},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
%extra y ticks={0,2,...,12},
%extra y tick style={
%    yticklabel pos=right
%},
tick style={thin,black},
xlabel=\large Classe,
ylabel=\large Frequenza,
colorbar,
colorbar style={
    /pgf/number format/fixed,
    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)}
]
\addplot[%
        ybar interval,
        area style,
        shading=stefan,
%        draw=none,
        shader=interp,
        samples=10,
        draw=black
        ] coordinates{%
             (1, 6)
             (2, 9)
             (3, 11)
             (4, 12)
             (5, 7)
             (6, 5)
             (7, 0)
             };
\end{axis}
%\end{figure}
\end{tikzpicture}
\end{document}
share|improve this question

1 Answer 1

up vote 7 down vote accepted

One option would be this one:

\documentclass[border=0.5mm,12pt]{standalone}

\usepackage{pgfplots,pgfplotstable}        % Grafici

\pgfplotsset{%
            mesh line legend/.style={legend image code/.code=\meshlinelegend#1},%
            /pgf/number format/use comma,%
            compat=newest,%
%            height=9cm,%
            width=12cm%
}


\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}
  }
}
\pgfdeclareverticalshading{stefan}{50bp}{
color(0.00000000000000bp)=(violet);
color(8.33333333333333bp)=(blue);
color(16.66666666666670bp)=(cyan);
color(25.00000000000000bp)=(green);
color(33.33333333333330bp)=(yellow);
color(41.66666666666670bp)=(orange);
color(50.00000000000000bp)=(red)
}
\begin{axis}[%
xtick=data,
/pgf/number format/fixed,
legend pos=outer north east,
ymajorgrids=true,
%ybar,
%x tick label as interval,
enlarge x limits=false,
x filter/.code=\pgfmathparse{#1-0.5},
%xmin=0, xmax=7,
ymin=0, ymax=14,
point meta min={0},
point meta max={12}, % original:14
yticklabel shift=2pt,
xticklabel shift=2pt,
minor ytick={0,0.4,...,14},
xticklabel style={text height=1.5ex},
xtick={0,1,...,7},
extra x ticks={0,1,...,7},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
%extra y ticks={0,2,...,12},
%extra y tick style={
%    yticklabel pos=right
%},
tick style={thin,black},
xlabel=\large Classe,
ylabel=\large Frequenza,
colorbar,
colorbar style={
    /pgf/number format/fixed,
    xticklabel shift=2pt,
    xticklabel style={text height=1.5ex},
    ymax=14%\pgfkeysvalueof{/pgfplots/point meta max},
},
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)}
]
\addplot[%
        ybar interval,
        area style,
        shading=stefan,
%        draw=none,
        shader=interp,
        samples=10,
        draw=black
        ] coordinates{%
             (1, 6)
             (2, 9)
             (3, 11)
             (4, 12)
             (5, 7)
             (6, 5)
             (7, 0)
             };
\end{axis}
%\end{figure}
\end{tikzpicture}
\end{document}

enter image description here

Another option would be:

\documentclass[border=0.5mm,12pt]{standalone}

\usepackage{pgfplots,pgfplotstable}        % Grafici

\pgfplotsset{%
            mesh line legend/.style={legend image code/.code=\meshlinelegend#1},%
            /pgf/number format/use comma,%
            compat=newest,%
%            height=9cm,%
            width=12cm%
}
\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}
  }
}
\pgfdeclareverticalshading{stefan}{50bp}{
color(0.00000000000000bp)=(violet);
color(8.33333333333333bp)=(blue);
color(16.66666666666670bp)=(cyan);
color(25.00000000000000bp)=(green);
color(33.33333333333330bp)=(yellow);
color(41.66666666666670bp)=(orange);
color(50.00000000000000bp)=(red)
}
\begin{axis}[%
xtick=data,
/pgf/number format/fixed,
legend pos=outer north east,
ymajorgrids=true,
%ybar,
%x tick label as interval,
enlarge x limits=false,
x filter/.code=\pgfmathparse{#1-0.5},
%xmin=0, xmax=7,
ymin=0, ymax=12,
point meta min={0},
point meta max={12},
yticklabel shift=2pt,
xticklabel shift=2pt,
minor ytick={0,0.4,...,14},
xticklabel style={text height=1.5ex},
xtick={0,1,...,7},
extra x ticks={0,1,...,7},
extra x tick style={
    xticklabel pos=right,
    xticklabel style={text depth=0pt}
},
%extra y ticks={0,2,...,12},
%extra y tick style={
%    yticklabel pos=right
%},
tick style={thin,black},
xlabel=\large Classe,
ylabel=\large Frequenza,
colorbar,
colorbar style={
    /pgf/number format/fixed,
    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)}
]
\addplot[%
        ybar interval,
        area style,
        shading=stefan,
%        draw=none,
        shader=interp,
        samples=10,
        draw=black
        ] coordinates{%
             (1, 6)
             (2, 9)
             (3, 11)
             (4, 12)
             (5, 7)
             (6, 5)
             (7, 0)
             };
\end{axis}
%\end{figure}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
thanks ! what have you modified?? –  FormlessCloud Jun 12 '12 at 10:14

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.