总得做点什么 2020-05-18 11:29 采纳率: 20%
浏览 451

核密度图怎么放在子图中?

请在一个图中生成2行2列子图,分别绘制第一列变量的条形图、直方图、核密度图、箱型图。并且子图之间的间距为0。

import numpy as np
import matplotlib.pyplot as plt
from pandas.core.frame import DataFrame
fig = plt.figure()
arr = np.random.randint(0,100,size = [10,10])
print(arr)
idx = np.arange(10)
ax1 = plt.subplot(221)
ax2 = plt.subplot(222)
ax3 = plt.subplot(223)
ax4 = plt.subplot(224)
ax1.bar(idx,[x[0] for x in arr])
ax2.hist([x[0] for x in arr],bins = 10)
ax3 = DataFrame([x[0] for x in arr])
ax3.plot.density()
ax4.boxplot([x[0] for x in arr])
plt.subplots_adjust(wspace = 0, hspace = 0)
plt.show()

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?