我尝试在条形图附近绘制坐标,它有效,但我收到了错误
! Dimension too large.
<recently read> \pgfmath@x
l.56 \end{axis}
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.
这是我的脚本
\pgfplotstableread[row sep=\\,col sep=&]{
interval & a & b & c \\
1 & 423.4191 & 406.7196 & 406.6987 \\
2 & 96.6418 & 95.6828 & 95.6796 \\
3 & 96.7403 & 95.6903 & 95.6870 \\
4 & 96.6698 & 95.7103 & 95.7072 \\
5 & 96.7684 & 95.7179 & 95.7146 \\
6 & 6.8072 & 1.8403 & 1.8406 \\
7 & 6.8072 & 1.8404 & 1.8408 \\
}\mydata
\pgfplotsset{/pgf/number format/use comma}
\pgfplotsset{compat=1.11,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd,yshift=-0.25em]
(0cm,0cm) rectangle (3pt,0.8em);},
},
}
\begin{tikzpicture}[font=\scriptsize]
%\draw[help lines,xstep=0.5,ystep=0.5,color=lightgray] (0,0) grid (6,5);
%\foreach \x in {0,1,...,6.5} { \node [anchor=north] at (\x,0) {\x}; }
%\foreach \y in {0,1,...,5} { \node [anchor=east] at (0,\y) {\y}; }
\begin{axis}[
ybar,
bar width=.125cm,
width=.5\textwidth,
height=.35\textwidth,
xtick=data,
xticklabels={(a),(b),(c),(d),(e),(f),(g)},
%xticklabel style={rotate=45,font=\scriptsize,yshift=1ex,anchor=north east},
xmajorgrids=false,
ymin=0,ymax=500,
ylabel={probability [ppm]},
%y label style={at={(0.05,0.5)}},
ymajorgrids=true,
yminorgrids=true,
minor y tick num=1,
ytick={0,100,200,300,400,500},
major grid style={lightgray},
minor grid style={lightgray},
every node near coord/.append style={rotate=60, anchor=west,font=\tiny},
%nodes near coords,
legend style={at={(0.5,1)},anchor=north,legend columns=-1,append after command={
\pgfextra{
\draw[draw=none,
drop shadow={fill=black, opacity=0.5, shadow xshift=2pt, shadow yshift=-2pt}]
(\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
}
},
},
blur shadow]
\addplot[nodes near coords,fill=lightgray] table[x=interval,y=a]{\mydata};
\addplot[fill=gray] table[x=interval,y=b]{\mydata};
\addplot[fill=darkgray] table[x=interval,y=c]{\mydata};
\legend{spc, mpc, mpc-c}
\end{axis}
\end{tikzpicture}
答案1
如果我将您的代码逐段删除,将其简化为最小(非)工作示例,则剩下以下内容:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{shadows.blur}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
blur shadow
]
\addplot coordinates{(0,0)(1,1)};
\end{axis}
\end{tikzpicture}
\end{document}
该代码将抛出您提到的错误,但从环境blur shadow
中删除该选项axis
可以使其正常工作。事实上,如果我采用您的代码,添加缺失的部分,然后删除blur shadow
,我会得到以下结果:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{shadows.blur}
\begin{document}
\pgfplotstableread[row sep=\\,col sep=&]{
interval & a & b & c \\
1 & 423.4191 & 406.7196 & 406.6987 \\
2 & 96.6418 & 95.6828 & 95.6796 \\
3 & 96.7403 & 95.6903 & 95.6870 \\
4 & 96.6698 & 95.7103 & 95.7072 \\
5 & 96.7684 & 95.7179 & 95.7146 \\
6 & 6.8072 & 1.8403 & 1.8406 \\
7 & 6.8072 & 1.8404 & 1.8408 \\
}\mydata
\pgfplotsset{/pgf/number format/use comma}
\pgfplotsset{compat=1.11,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd,yshift=-0.25em]
(0cm,0cm) rectangle (3pt,0.8em);},
},
}
\begin{tikzpicture}[font=\scriptsize]
%\draw[help lines,xstep=0.5,ystep=0.5,color=lightgray] (0,0) grid (6,5);
%\foreach \x in {0,1,...,6.5} { \node [anchor=north] at (\x,0) {\x}; }
%\foreach \y in {0,1,...,5} { \node [anchor=east] at (0,\y) {\y}; }
\begin{axis}[
ybar,
bar width=.125cm,
width=.5\textwidth,
height=.35\textwidth,
xtick=data,
xticklabels={(a),(b),(c),(d),(e),(f),(g)},
%xticklabel style={rotate=45,font=\scriptsize,yshift=1ex,anchor=north east},
xmajorgrids=false,
ymin=0,ymax=500,
ylabel={probability [ppm]},
%y label style={at={(0.05,0.5)}},
ymajorgrids=true,
yminorgrids=true,
minor y tick num=1,
ytick={0,100,200,300,400,500},
major grid style={lightgray},
minor grid style={lightgray},
every node near coord/.append style={rotate=60, anchor=west,font=\tiny},
%nodes near coords,
legend style={at={(0.5,1)},anchor=north,legend columns=-1,append after command={
\pgfextra{
\draw[draw=none,
drop shadow={fill=black, opacity=0.5, shadow xshift=2pt, shadow yshift=-2pt}]
(\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
}
},
},
%blur shadow %%% commented out
]
\addplot[nodes near coords,fill=lightgray] table[x=interval,y=a]{\mydata};
\addplot[fill=gray] table[x=interval,y=b]{\mydata};
\addplot[fill=darkgray] table[x=interval,y=c]{\mydata};
\legend{spc, mpc, mpc-c}
\end{axis}
\end{tikzpicture}
\end{document}