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 can i add in this plot the extra x and y ticks ? 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}
\begin{axis}[%
ybar,
/pgf/number format/fixed,
xtick=data,
tick style={thin,black},
ymin=0, ymax=12,
point meta min={0},
minor ytick={0,0.4,...,12},
point meta max={12},
yticklabel shift=2pt,
xticklabel shift=2pt,
xlabel=\large {Classe},
ylabel=\large {Frequenza},
ymajorgrids=true,
xticklabel interval boundaries,
symbolic x coords={%
                  $1$,
                  $2$,
                  $3$,
                  $4$,
                  $5$,
                  $6$,
                  $7$
                  },
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,
        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
    
Why would you define those symbolic coordinates? It doesn't make much sense to use $1$, the numbers will be printed exactly the same way, but it's causing unnecessary problems, as you have noticed. –  Jake Jun 11 '12 at 20:24
    
see the pictures i have define the symbolic coordinates because i want the effect to the right... i have take it from this guide: lorenzopantieri.net/LaTeX_files/Grafici.pdf page 25 –  FormlessCloud Jun 11 '12 at 20:37
1  
That's not a very good way to change the alignment. I've added an answer showing how I would do it, and you can also take a look at Zero space between bars in pgfplots bar graph for another approach. –  Jake Jun 11 '12 at 21:06
add comment

1 Answer

up vote 5 down vote accepted

You shouldn't use symbolic coordinates just to change the alignment. Symbolic coordinates are quite unflexible. You can get the same alignment by simply setting x tick label as interval with normal numerical coordinates.

\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}
\begin{axis}[%
ybar,
/pgf/number format/fixed,
xtick=data,
tick style={thin,black},
ymin=0, ymax=12,
point meta min={0},
minor ytick={0,0.4,...,12},
point meta max={12},
yticklabel shift=2pt,
xticklabel shift=2pt,
xlabel=\large {Classe},
ylabel=\large {Frequenza},
ymajorgrids=true,
%xticklabel interval boundaries,
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);},
x tick label as interval,
extra x ticks=3,
extra x tick labels=3.5,
extra x tick style={
red,
x tick label as interval=false
},
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,
        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 answer
add comment

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.