使用 matplotlib 在箱线图中显示传单颜色
Flier colors in boxplot with matplotlib
根据documentation,Axes.boxplot
函数将字典flierprop
作为参数来定义异常值的属性。不幸的是,我找不到关于这本词典的文档。特别是,我想定义标记边框的颜色。
默认情况下,绘制空心圆圈。可以设置人脸颜色,as shown in the example。尽管如此,圆形边框始终是一条黑线。我尝试使用 color
和 markercolor
键(前者无效,后者产生错误)。
如何设置标记线的颜色?
要设置标记颜色,请使用 属性 markerfacecolor
但对于边框颜色 - markeredgecolor
:
import matplotlib.pyplot as plt
import numpy as np
# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)
# plot. Set color of marker edge
flierprops = dict(marker='o', markerfacecolor='r', markersize=12,
linestyle='none', markeredgecolor='g')
plt.boxplot(data, flierprops=flierprops)
plt.show()
根据@Spiros 的说法,这里记录了 flierprops 字典,就像其他箱线图属性一样:http://matplotlib.org/users/dflt_style_changes.html?highlight=flierprops#boxplot
根据documentation,Axes.boxplot
函数将字典flierprop
作为参数来定义异常值的属性。不幸的是,我找不到关于这本词典的文档。特别是,我想定义标记边框的颜色。
默认情况下,绘制空心圆圈。可以设置人脸颜色,as shown in the example。尽管如此,圆形边框始终是一条黑线。我尝试使用 color
和 markercolor
键(前者无效,后者产生错误)。
如何设置标记线的颜色?
要设置标记颜色,请使用 属性 markerfacecolor
但对于边框颜色 - markeredgecolor
:
import matplotlib.pyplot as plt
import numpy as np
# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)
# plot. Set color of marker edge
flierprops = dict(marker='o', markerfacecolor='r', markersize=12,
linestyle='none', markeredgecolor='g')
plt.boxplot(data, flierprops=flierprops)
plt.show()
根据@Spiros 的说法,这里记录了 flierprops 字典,就像其他箱线图属性一样:http://matplotlib.org/users/dflt_style_changes.html?highlight=flierprops#boxplot