matplotlib 箱线图 叠加 直方图

matplotlib 箱线图 叠加 直方图

OriginPro 里箱线图叠加直方图很不错,尝试了使用matplotlib达到类似效果

import matplotlib.pyplot as plt
import numpy as np
## 借用帮助文件中的数据
# Fixing random state for reproducibility
np.random.seed(19680801)
# 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))

fig=plt.figure()
# basic plot
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
ax1 = fig.add_axes([left, bottom, width, height])

ax1.boxplot(data)
ax1.set_title('basic plot')
ax1.set_ylim(-150,250)

left, bottom, width, height = 0.58, 0.1, 0.1, 0.8
ax2 = fig.add_axes([left, bottom, width, height])
# ax2=fig.add_axes([0.2,0,0.6,0.5])
ax2.hist(data,orientation='horizontal',density=True,bins=10, align='left')
ax2.set_ylim(-150,250)
plt.axis('off')
plt.show()

箱线图叠加直方图

发布了2 篇原创文章 · 获赞 1 · 访问量 1157

猜你喜欢

转载自blog.csdn.net/yingfly/article/details/104097482