我正在尝试为数据集中的每个特征制作直方图的子图。
以下代码是我已经尝试解决的问题。考虑火车数据集,该数据集有9列,我想将其绘制在3 * 3子图中。
import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=3, ncols=3)
i=0
for row in ax:
for col in row:
train.iloc[:,i].hist()
i=i+1
我在最后一个子图中得到所有直方图。
答案 0 :(得分:0)
这是我的建议:
import matplotlib.pyplot as plt
import random
for i in range(1,7):
# Cut your figure into 3 row and 3 columns
# and create the plot in the i subplot.
# here I used the f-string formatting that is available from python3.6
plt.subplot(f'33{i}')
plt.hist(random.randrange(0, 10))
您可以在这个令人惊叹的网站上找到更多的想法:http://central.maven.org/maven2/edu/stanford/nlp/stanford-parser/3.9.2/
答案 1 :(得分:0)
pandas.DataFrame.hist可以采用ax
参数,这是要使用的Matplotlib轴。