python-2.7 - plt.boxplot(data, vert = False) - 每个箱线图添加一个数据点 - python 2.7,Matplotlib 1.5.3

标签 python-2.7 matplotlib boxplot

一直在尝试向我的箱线图添加一个点。我只想在下图中添加一个点作为黑色点。

data_2 = [pd.read_csv(data).values for data in os.listdir(wd)]
bp = plt.boxplot(data_2, labels = labels, vert = False, showfliers = False)
plt.show()

关于我应该如何处理它有什么想法吗? You can click here to see the pic

enter image description here

最佳答案

您可以在箱线图完成后绘制单个点,只需给出适当的坐标即可:

import numpy as np
import matplotlib.pyplot as plt

data = np.array( [
np.random.normal( 0.19, 0.1, 100 ),
np.random.normal( 0.17, 0.1, 100 ),
np.random.normal( 0.11, 0.1, 100 ),
np.random.normal( 0.16, 0.1, 100 ),
np.random.normal( 0.15, 0.1, 100 ) ] ).T

labels = [ 'pred2012', 'pred2007', 'pred2002', 'pred1995', 'pred1988' ]

fig, ax = plt.subplots()
ax.boxplot( data, labels=labels, vert = False, showfliers = False)
ax.plot( -0.1, 4, marker='o' ) 
ax.plot( 0.3, 3, marker='*', markersize=20 ) 
plt.savefig( 'boxplot.png' )
plt.show()

enter image description here

关于python-2.7 - plt.boxplot(data, vert = False) - 每个箱线图添加一个数据点 - python 2.7,Matplotlib 1.5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42025387/

相关文章:

python - Tkinter 索引词问题

python - 尽管设置了 alpha,3D 表面仍不透明

python - 截断数据的密度图

r - 将条形图与箱线图组合成一个图形

python - 在 Python 中读取/写入文件

python - super 初始化与父级.__init__

python - python2中的特殊字符编码

python - 如果 yticks 太多,Seaborn 会自动隐藏 yticks

python - matplotlib:多个箱形图的插入轴

r - 仅对箱线图中的中位数着色