python - 是否可以在子图中控制 xlabel 步进标签?
问题描述
我相信这是一个关于子情节的老问题。但是,我无法找到我的答案。
问题:
是否可以让我subplot
同样踩到x-label
?
y_label = 'db_server_6a_2018_df_IL1-A'
f, ax_list = plt.subplots(12, 1, gridspec_kw = {
'height_ratios': [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
'width_ratios': [30]
}, figsize=(20, 40))
for month in range(1, 12 + 1):
start_dt = datetime.datetime(2018, month, 1)
end_dt = start_dt + relativedelta(months=1)
window_df = df[(start_dt < df['Time']) & (df['Time'] <= end_dt)]
ax = ax_list[month-1]
ax.plot(window_df['Time'], window_df[y_label])
ax.set_ylabel(start_dt.strftime('%B'))
ax.set_xlabel('datetime')
f.savefig(y_label + '.png')
解决方案
您是否已经尝试设置 xticks() 和 xlim(),即分别为每个子图设置应放置刻度的新位置列表并设置新 x 轴限制的元组?
它们也应该与子图很好地配合使用。
另一种解决方案可能是使用:
plt.subplot(something, sharex=ax, sharey=ax)
在哪里,如文档中所述
sharex, sharey : Axes, optional
Share the x or y axis with sharex and/or sharey.
The axis will have the same limits, ticks, and scale as the axis of the shared axes.
PS我不能写评论,因为我没有足够的声誉。
推荐阅读
- r - How to import a graph from Cytoscape to R?
- javascript - 在传递下一个数组索引之前删除每个字母?
- python - 如何在 IF 中使用结果来吐出 True/False?
- c# - How to call a function from razorview to cshtml.cs
- github-pages - Github 环境
- svelte - 如何在 Svelte 中动态渲染组件?
- excel - Send all Due to date and names in one email
- javascript - 在 Javascript 类中完成 Async Promise 时出现问题
- r - R:删除图表中没有数据(NA)的范围x轴
- ms-word - 更改脚注的顺序