你能帮我一下吗?
我对箱线图的每个轴都使用了自定义颜色,但它们的异常值与该颜色不匹配。
这是我目前所拥有的
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\usetikzlibrary{pgfplots.statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
boxplot/draw direction = y,
x axis line style = {opacity=0},
axis x line* = bottom,
axis y line = left,
enlarge y limits,
ymajorgrids,
xtick = {1, 2, 3, 4},
xticklabel style = {align=center, font=\small},
xticklabels = {A, B, C, D},
xtick style = {draw=none},
ylabel = {LoC},
]
\addplot+[
boxplot prepared={
lower whisker=1,
lower quartile=2,
median=3,
upper quartile=4,
upper whisker=5
},
color=green,
fill=green,
draw=black
] coordinates {(0, 6)};
\addplot+[
boxplot prepared={
lower whisker=0.5,
lower quartile=2,
median=3,
upper quartile=3.5,
upper whisker=5
},
color=blue,
fill=blue,
draw=black
] coordinates {(0, 5.7)};
\addplot+[
boxplot prepared={
lower whisker=0,
lower quartile=1,
median=2,
upper quartile=4,
upper whisker=5.5
},
color=red,
fill=red,
draw=black
] coordinates {(0, 6)};
\end{axis}
\end{tikzpicture}
\end{document}
这是我得到的结果
有什么建议么?
提前致谢,Humberto
答案1
因为看起来mark
s 的颜色必须额外给出mark options
(见下文的 MWE)。
有趣的是,改变\addplot+
为(只是)\addplot
异常值根本没有显示出来。连同“奇怪”的行为\addplot+
不考虑非异常值的颜色的“奇怪”行为,这可能是一个错误。如果您也这么认为,请考虑在PGFlots 问题追踪器。
% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
boxplot/draw direction=y,
]
\addplot+[
boxplot prepared={
lower whisker=1,
lower quartile=2,
median=3,
upper quartile=4,
upper whisker=5,
},
fill=green,
draw=black,
% ==============
% added
mark options={
fill=green,
draw=black,
},
% ==============
] coordinates {(0, 6)};
\end{axis}
\end{tikzpicture}
\end{document}