如何将条形的填充从水平转换为垂直?
\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}
}
}
\pgfdeclarehorizontalshading{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}[%
ybar,
xtick=data,
/pgf/number format/fixed,
legend pos=outer north east,
ymajorgrids=true,
%xmin=0, xmax=7,
ymin=0, ymax=14,
point meta min={0},
point meta max={14},
yticklabel shift=2pt,
xticklabel shift=2pt,
x tick label as interval,
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}
答案1
谢谢杰克
抱歉,我没有注意到!
\pgfdeclarverticalshading 改变这个!
\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}[%
ybar,
xtick=data,
/pgf/number format/fixed,
legend pos=outer north east,
ymajorgrids=true,
%xmin=0, xmax=7,
ymin=0, ymax=14,
point meta min={0},
point meta max={14},
yticklabel shift=2pt,
xticklabel shift=2pt,
x tick label as interval,
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}