Skip to main content
 首页 » 编程设计

python之matplotlib:子图重叠的 ylabels

2024年11月01日10www_RR

我有三个子图共享 x 轴。我需要子图之间的 hspace 为 0.0,但子图的 y 标签重叠。

ylabels of subplots overlap

有什么方法可以将每个子图的极端 y 标签向下或向上移动一点点(就像我在右侧的 mspaint 中手动所做的那样)?

彼得

请您参考如下方法:

有一个专门用于此目的的代码格式化器类。
http://matplotlib.org/api/ticker_api.html#matplotlib.ticker.MaxNLocator

from matplotlib.ticker import MaxNLocator 
ax2.yaxis.set_major_locator(MaxNLocator(prune='upper'))  #remove highest label so it wont overlapp with stacked plot. 

编辑: 实际上这不会移动它们,只是删除重叠的刻度。