当用创建条形图时ybar
,最后添加的图表有一个dashed
轮廓,我似乎不明白为什么。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=left,
xmajorgrids,
ymajorgrids,
xmin=0,
xmax=7,
ymin=60,
ymax=80,
bar width=5mm
]
\addplot+[ybar,mark=0,fill=black!80,draw=black]
coordinates {
(1,77.071)
};
\addplot+[ybar,mark=0,fill=black!30,draw=black]
coordinates {
(2,70.256)
};
\addplot+[ybar,mark=0,fill=black!30,draw=black]
coordinates {
(3,65.383)
};
\addplot+[ybar,mark=0,fill=black!30,draw=black]
coordinates {
(4,66.077)
};
\addplot+[ybar,mark=0,fill=black!30,draw=black]
coordinates {
(5,75.808)
};
\addplot+[ybar,mark=0,fill=black!10,draw=black]
coordinates {
(6,77.635)
};
\end{axis}
\end{tikzpicture}
\end{document}
输出:
但是,当我“添加”较少的图时,这个问题就消失了,如下所示:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=left,
xmajorgrids,
ymajorgrids,
xmin=0,
xmax=7,
ymin=60,
ymax=80,
bar width=5mm
]
\addplot+[ybar,mark=0,fill=black!80,draw=black]
coordinates {
(1,77.071)
};
\addplot+[ybar,mark=0,fill=black!30,draw=black]
coordinates {
(2,70.256)(3,65.383)(4,66.077)(5,75.808)
};
\addplot+[ybar,mark=0,fill=black!10,draw=black]
coordinates {
(6,77.635)
};
\end{axis}
\end{tikzpicture}
\end{document}
输出:
答案1
此行为由 控制cycle list
。如果你查看 pgfplots 手册第 214 页,你会发现
这解释了为什么第 6 个图有虚线。解决此问题的一种方法是添加solid
到图中,或者您可以创建并使用自己的循环列表。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotscreateplotcyclelist{Syphirint}{
fill=black!80,draw=black,solid,mark=none\\
fill=black!30,draw=black,solid,mark=none\\
fill=black!30,draw=black,solid,mark=none\\
fill=black!30,draw=black,solid,mark=none\\
fill=black!30,draw=black,solid,mark=none\\
fill=black!10,draw=black,solid,mark=none\\
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[cycle list name=Syphirint,
axis lines=left,
xmajorgrids,
ymajorgrids,
xmin=0,
xmax=7,
ymin=60,
ymax=80,
bar width=5mm
]
\addplot+[ybar]
coordinates {
(1,77.071)
};
\addplot+[ybar]
coordinates {
(2,70.256)
};
\addplot+[ybar]
coordinates {
(3,65.383)
};
\addplot+[ybar]
coordinates {
(4,66.077)
};
\addplot+[ybar]
coordinates {
(5,75.808)
};
\addplot+[ybar]
coordinates {
(6,77.635)
};
\end{axis}
\end{tikzpicture}
\end{document}