How to set properties on matplotlib subplots

plt.subplot returns a subplot object which is a type of axes object. It has two methods for adding axis labels: set_xlabel and set_ylabel:

ax = plt.subplot('111')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')

You could also call plt.xlabel and plt.ylabel (like you did before) and specify the axes to which you want the label applied.

ax = plt.subplot('111')
plt.xlabel('X Axis', axes=ax)
plt.ylabel('Y Axis', axes=ax)

Since you only have one axes, you could also omit the axes kwarg since the label will automatically be applied to the current axes if one isn’t specified.

ax = plt.subplot('111')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)