python - 在直方图的每个子图中标记 bin
问题描述
我有一个数据框,df 有 29 行 x 24 列维度
Index 0.0 5.0 34.0 ... 22.0
2017-08-03 00:00:00 10 0 10 0
2017-08-04 00:00:00 20 60 1470 20
2017-08-05 00:00:00 0 58 0 24
2017-08-06 00:00:00 0 0 480 24
2017-09-07 00:00:00 0 0 0 25
: : : : :
: : : : :
2017-09-30 00:00:00
我打算为表示直方图中的一列的每个子图标记箱。我已经能够使用此代码在每个子图中为每列绘制直方图
fig = plt.figure(figsize = (15,20))
ax = fig.gca()
#Initialize the figure
plt.style.use('seaborn-darkgrid')
df.hist(ax = ax)
但是,每个子图的 bin 标签相距很远,并且 bin 标签没有由 x 轴上的范围明确指定,这很难解释。我已经在 plt.hist 中查看了 Aligning bins to xticks但是当涉及到子图时,它并没有明确解决标记 bins 的问题。任何帮助都会很棒...
我也试过这个,但我得到 ValueError: too many values to unpack (expected 2)
x=[0,40,80,120,160,200,240,280,320]
fig = plt.figure(figsize = (15,20))
ax = fig.gca()
# Initialize the figure
plt.style.use('seaborn-darkgrid')
n,bins= plt.hist(df,bins= x)
#labels & axes
plt.locator_params(nbins=8, axis='x')
plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
plt.title('Daily occurrence',fontsize=16)
plt.xlabel('Number of occurrence',fontsize=12)
plt.ylabel('Frequency',fontsize=12)
plt.xticks(x)
plt.xlim(0,320)
解决方案
推荐阅读
- python - AttributeError:'function'对象没有属性'route'
- mysql - 如何在 MySQL 数据库和节点中保存表情符号?
- flutter - Flutter 后台进程甚至 App 已关闭
- identityserver4 - 如何将 Web API 与在 VS Studio(托管 Blazor WASM 和 Identity 模板)中创建的 IdentityServer 分离为自己的项目?
- c# - 为什么现在阻止我的 IP 从托管在 Azure 中的 ASP.NET Core 应用程序通过 Mailkit 发送电子邮件?
- javascript - 尽管 innerHTML 没有明确的新行、制表符或
- rust - Warp 中的 API 密钥验证 (Rust)
- powershell - 每个无法访问或超时的 ping 之间的 Powershell 时间延迟
- sql-server - 仅在调试模式下在发布中包含 PostDeployment sql 脚本
- c++ - 未执行的函数抛出异常