matplotlib .ylabel() beheben: AttributeError: 'AxesSubplot' object has no attribute 'ylabel'
English
Deutsch
Problem:
Die ylabel-Beschriftung eines matplotlib-Plots soll mit .ylabel("Meine ylabel-Beschriftung") gesetzt werden, aber es wird eine Fehlermeldung wie folgende angezeigt
attribute_error.txt
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-28a87d95bccc> in <module>
---> 11 axs[0].ylabel("My ylabel")
AttributeError: 'AxesSubplot' object has no attribute 'ylabel'Lösung
.set_ylabel("Meine ylabel-Beschriftung") anstelle von .ylabel("Meine ylabel-Beschriftung") verwenden!
Während
plt_ylabel_example.py
from matplotlib import pyplot as plt
plt.ylabel("My ylabel")funktioniert, muss bei einem Axes-Objekt wie dem von plt.subplots() zurückgegebenen set_ylabel() verwendet werden!
plt_set_ylabel.py
from matplotlib import pyplot as plt
fig, axs = plt.subplots(2, 1)
# ...
axs[0].set_ylabel("My ylabel")Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow