python - 如何使用此方法制作子图
问题描述
我正在尝试为数据集中的每个特征制作直方图的子图。
以下代码是我已经尝试解决的问题。考虑训练数据集,它有 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
我在最后一个子图中得到了所有直方图。
解决方案
这是我的建议:
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))
你可以在这个令人惊叹的网站上找到更多想法:Python Graph Gallery
推荐阅读
- ibm-cloud - AppId SAML:签名请求
- javascript - 使用 javascript 传递值 MySQL 查询
- java - ProgressDialog 继续显示,尽管被取消和隐藏
- c# - MVC 引导轮播
- c# - 使用 C# 或 SQL Server 存储过程检查文本字段以阻止阿拉伯数字
- javascript - Vue.JS 表格数据未在行中显示
- java - Azure 函数的 CosmosDBInput 绑定未使用 HttpTrigger 中定义的路径变量
- mysql - 当我删除每个表时,phpMyAdmin FK 约束差异操作
- mongodb - Mongoose 查询根据嵌套文档中的值列出文档
- javascript - 当我们可以直接调用方法时,为什么我们需要在javascript中调用或应用方法?