我怎样才能在此图中添加额外的 x 和 y 刻度?
\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}
答案1
您不应该只使用符号坐标来更改对齐方式。符号坐标非常不灵活。您只需x tick label as interval
使用普通数字坐标进行设置即可获得相同的对齐方式。
\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}