matplotlib:箱线图对象中的传单设置不正确
matplotlib: Fliers in boxplot object not setting correctly
我正在努力将箱线图中的传单标记更改为我选择的自定义颜色。在前三个值之后,它恢复为默认值。我看到有几个与此相关的 matplotlib 问题,有解决办法吗?
在此先感谢您的帮助!
import matplotlib.pyplot as plt
x = [0.15, 0.11, 0.06, 0.06, 0.12, 0.56]
y = [x, x, x, x, x, x]
boxes = plt.boxplot(y, sym="o")
cols = ['green', 'red', 'blue', 'orange', 'purple', 'black']
for f, fc in zip(boxes['fliers'], cols):
f.set_color(fc)
f.set_markersize(40)
f.set_alpha(0.6)
f.set_markeredgecolor("None")
f.set_marker('.')
plt.show()
你的代码对我来说工作正常,你的 matplotlib 版本是多少?
原始问题中给出的代码在 matplotlib 的开发版本中不起作用 v1.5dev
。这是因为set_color
方法没有作用于facecolor,应该是set_markerfacecolor
。一个完整的工作示例是:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = [0.15, 0.11, 0.06, 0.06, 0.12, 0.56]
y = [x, x, x, x, x, x]
boxes = plt.boxplot(y,
flierprops={'alpha':0.6,
'markersize': 40,
'markeredgecolor': 'None',
'marker': '.'
})
cols = ['green', 'red', 'blue', 'orange', 'purple', 'black']
for f, fc in zip(boxes['fliers'], cols):
f.set_markerfacecolor(fc)
plt.show()
为了便于阅读,我还移动了要在 flierprops
中设置的所有固定属性。
我正在努力将箱线图中的传单标记更改为我选择的自定义颜色。在前三个值之后,它恢复为默认值。我看到有几个与此相关的 matplotlib 问题,有解决办法吗?
在此先感谢您的帮助!
import matplotlib.pyplot as plt
x = [0.15, 0.11, 0.06, 0.06, 0.12, 0.56]
y = [x, x, x, x, x, x]
boxes = plt.boxplot(y, sym="o")
cols = ['green', 'red', 'blue', 'orange', 'purple', 'black']
for f, fc in zip(boxes['fliers'], cols):
f.set_color(fc)
f.set_markersize(40)
f.set_alpha(0.6)
f.set_markeredgecolor("None")
f.set_marker('.')
plt.show()
你的代码对我来说工作正常,你的 matplotlib 版本是多少?
原始问题中给出的代码在 matplotlib 的开发版本中不起作用 v1.5dev
。这是因为set_color
方法没有作用于facecolor,应该是set_markerfacecolor
。一个完整的工作示例是:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = [0.15, 0.11, 0.06, 0.06, 0.12, 0.56]
y = [x, x, x, x, x, x]
boxes = plt.boxplot(y,
flierprops={'alpha':0.6,
'markersize': 40,
'markeredgecolor': 'None',
'marker': '.'
})
cols = ['green', 'red', 'blue', 'orange', 'purple', 'black']
for f, fc in zip(boxes['fliers'], cols):
f.set_markerfacecolor(fc)
plt.show()
为了便于阅读,我还移动了要在 flierprops
中设置的所有固定属性。