在pyplot中与三个子图中的两个共享yaxis标签

Dur*_*tta 9 python matplotlib

我有以下代码生成显示的图.

mport matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec
import numpy as np

One = range(1,10)
Two = range(5, 14) 
l = len(One)
fig = plt.figure(figsize=(10,6))
gs = gridspec.GridSpec(3, 1, height_ratios=[5, 3, 3]) 

ax0 = plt.subplot(gs[0])
ax0.bar(range(l), Two)
plt.ylabel("Number of occurrence")

ax1 = plt.subplot(gs[1], sharey=ax0)
ax1.bar(range(l), Two)

ax2 =  plt.subplot(gs[2])
ax2.bar(range(l), One)

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我希望ylabel("出现次数")在第一个和第二个图之间共享,也就是说,它应该出现在第一个和第二个图的中间左侧.我怎么做?

Bra*_*rad 0

这不是一个非常复杂的解决方案,但这行得通吗?代替

plt.ylabel("Number of occurrence")
Run Code Online (Sandbox Code Playgroud)

plt.ylabel("Number of occurrence", verticalalignment = 'top')
Run Code Online (Sandbox Code Playgroud)

[编辑]

对于我的 64 位 python (2.7.3) 版本,我需要进行一些小更改

plt.ylabel("Number of occurrence", horizontalalignment = 'right')
Run Code Online (Sandbox Code Playgroud)

这就是我的样子,这不是你想要的吗?

在此输入图像描述