需要在 X 轴标签的子图之间添加空间,也许删除轴凹口的标签

发布于 2024-10-19 16:21:57 字数 992 浏览 0 评论 0原文

希望在绘制的图表之间添加垂直空间以允许显示 X 轴标签:

每个图表都需要有空间来显示日期,目前最后 2 个图表是唯一显示的图表,因为图表重叠了。

我也很好奇,我是否真的可以删除标记为星期四/星期五的图表上方 X 轴的凹口标签,即底部 X 轴是唯一显示的。 Y 轴也是如此,但只有左侧的图表显示了比例。

*不幸的是,我无法发布图片来显示这一点,因为我没有足够的代表。

代码片段:

import mathlib.pyplot as pyplot
fig = pyplot.figure()
ax1 = fig.add_subplot(4,2,1)
ax1.set_yscale('log')
ax2 = fig.add_subplot(4,2,2, sharex=ax1, sharey=ax1)
ax3 = fig.add_subplot(4,2,3, sharex=ax2, sharey=ax2)
ax4 = fig.add_subplot(4,2,4, sharex=ax3, sharey=ax3)
ax5 = fig.add_subplot(4,2,5, sharex=ax4, sharey=ax4)
ax6 = fig.add_subplot(4,2,6, sharex=ax5, sharey=ax5)
ax7 = fig.add_subplot(4,2,7, sharex=ax6, sharey=ax6)
ax1.plot(no_dict["Saturday"],'k.-',label='Saturday')
ax1.set_xlabel('Saturday')
ax1.axis([0,24,0,10000])
pyplot.suptitle('Title')
pyplot.xlabel('Hour in 24 Hour Format')
ax2.plot(no_dict["Sunday"],'b.-',label='Sunday')
ax2.set_xlabel('Sunday')
...

太拥挤

Looking to add in vertical space between plotted graphs to allow a X-Axis label to show:

Each graph needs to have space to show the day, currently the last 2 graphs are the only one's that show simply because the graphs are overlapping it.

Also curious if I could actually remove the notch labels for the X-Axis for the graphs above the one's marked Thursday/Friday, i.e. the bottom X-axis is the only one that shows. Same for the Y-Axis, but only the graphs on the left having the scale shown.

*Unfortunately I can't post an image to show this since I don't have enough rep.

Code snippet:

import mathlib.pyplot as pyplot
fig = pyplot.figure()
ax1 = fig.add_subplot(4,2,1)
ax1.set_yscale('log')
ax2 = fig.add_subplot(4,2,2, sharex=ax1, sharey=ax1)
ax3 = fig.add_subplot(4,2,3, sharex=ax2, sharey=ax2)
ax4 = fig.add_subplot(4,2,4, sharex=ax3, sharey=ax3)
ax5 = fig.add_subplot(4,2,5, sharex=ax4, sharey=ax4)
ax6 = fig.add_subplot(4,2,6, sharex=ax5, sharey=ax5)
ax7 = fig.add_subplot(4,2,7, sharex=ax6, sharey=ax6)
ax1.plot(no_dict["Saturday"],'k.-',label='Saturday')
ax1.set_xlabel('Saturday')
ax1.axis([0,24,0,10000])
pyplot.suptitle('Title')
pyplot.xlabel('Hour in 24 Hour Format')
ax2.plot(no_dict["Sunday"],'b.-',label='Sunday')
ax2.set_xlabel('Sunday')
...

too crowded

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女七分熟 2024-10-26 16:21:57

使用 subplots_adjust。在您的情况下,这看起来不错:

fig.subplots_adjust(hspace=.5)

要删除刻度标签,请执行以下操作:

ax1.set_xticklabels([])

yticklabels 类似。但是,您不能与具有刻度标签的图共享 x 轴。

在此处输入图像描述

Use subplots_adjust. In your case this looks good:

fig.subplots_adjust(hspace=.5)

to remove the tick labels do this:

ax1.set_xticklabels([])

Similar for the yticklabels. However, you cannot share the x-axis with the plots that do have tick labels.

enter image description here

幻梦 2024-10-26 16:21:57

方法调整该子图的轴位置:

bbox=plt.gca().get_position()
offset=-.03
plt.gca().set_position([bbox.x0, bbox.y0 + offset, bbox.x1-bbox.x0, bbox.y1 - bbox.y0])

要更改某个子图周围的间距(而不是全部子图),您可以使用以下 0,子图向下移动。如果偏移量> 0,子图向上移动。

请注意,如果偏移量太大以至于子图的新位置与另一个子图重叠,则子图将会消失。

To change the spacing around a certain subplot, instead of all of them, you can adjust the position of the axes of that subplot using:

bbox=plt.gca().get_position()
offset=-.03
plt.gca().set_position([bbox.x0, bbox.y0 + offset, bbox.x1-bbox.x0, bbox.y1 - bbox.y0])

If offset < 0, the subplot is moved down. If offset > 0, the subplot is moved up.

Note that the subplot will disappear if offset is so big that the new position of the subplot overlaps with another subplot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文