When creating a two-panel subplot with shared axis, I can specify the label for each axes...
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, sharey=True, sharex=True)
axes[0].set_ylabel('ylabel-1')
axes[1].set_ylabel('ylabel-2')
plt.tight_layout()
However, when I use Pandas to plot on those axes, the shared label goes missing
import matplotlib.pyplot as plt
import pandas as pd
fig, axes = plt.subplots(1, 2, sharey=True, sharex=True)
pd.DataFrame([1,2,3]).plot(ax=axes[0])
pd.DataFrame([3,2,1]).plot(ax=axes[1])
axes[0].set_ylabel('ylabel-1')
axes[1].set_ylabel('ylabel-2')
plt.tight_layout()
How can I get that label to show?
As described here, the label exists, but it is not visible.
Add this line to get the label to be visible.
axes[1].yaxis.get_label().set_visible(True)
For example:
fig, axes = plt.subplots(1, 2, sharey=True, sharex=True)
pd.DataFrame([1,2,3]).plot(ax=axes[0])
pd.DataFrame([3,2,1]).plot(ax=axes[1])
axes[0].set_ylabel('xlabel')
axes[1].set_ylabel('ylabel')
axes[1].yaxis.get_label().set_visible(True)
plt.tight_layout()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With