一直在尝试向我的箱线图添加一个点。我只想在下图中添加一个点作为黑色点。
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
最佳答案
您可以在箱线图完成后绘制单个点,只需给出适当的坐标即可:
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()
关于python-2.7 - plt.boxplot(data, vert = False) - 每个箱线图添加一个数据点 - python 2.7,Matplotlib 1.5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42025387/