python - 将数据框中的所有列绘制到单个图 Python
问题描述
我有一个包含 x 列的数据框(x 因用户的输入而异)。我希望能够将每个数据帧中的所有列绘制为单个直方图。
到目前为止,此循环的一些代码如下所示:
for var_name in variables:
df_var = (rand_sample.filter(like=str(var_name))) # filter on each variable for comparison
print(df_var)
# Plot Frequency
fig = plt.subplots(figsize=(12, 8))
plt.hist([df_var], alpha=0.35, bins=bin_size)
plt.title(str(j), fontsize=18)
plt.xlabel('Porosity Density', fontsize=15)
plt.ylabel('Frequency', fontsize=15)
plt.grid(True)
plt.show()
variables
以前用想要的字符串制作的列表在哪里,我正在过滤以组合在一起df_var
。
我得到错误:
ValueError: cannot copy sequence with size 107574 to array axis with dimension 2
这意味着2 columns
试图在1 column
这里绘制 - 我明白这一点;我只是不知道如何编写代码来plt.hist([df_var]...)
为任意数量的列工作。
解决方案
推荐阅读
- python - python发行版的安装
- typescript - Github 操作失败构建 Typescript 但在本地机器上工作
- linux - Bash - 使用 socat 的代理服务器
- uml - UML 状态图定义
- html - django 指向 \ 错误的 URL href
- here-api - 来自 HERE API (bcp 47) 的语言响应不正确(瑞典语)
- bash - 如何在文件中找到最常用的名称?
- python - python socket并行发送和接收
- git - GitKraken 在 Windows 上签出分支失败并删除了文件
- selenium - Locust、Realbrowserlocust 和从配置文件 .ymal 运行