Reputation: 74
From the Matplotlib's official website I can get that the function 'ax.set()' can bset attributes.But I haven't known what attributes can I set actually.For instance:
from matplotlib import pyplot as plt
import numpy as np
import matplotlib
fig=plt.figure(
figsize=(15,6),
dpi=120,
)
#definition layout
layout=(2,4)
#create
axes=fig.subplots(*layout)
ax_plot_function=axes[0][0]
ax_scatter=axes[0][1]
#plot the first axes
props = {
'title': 'function_example$f(x)=cos(x)$',
'xlabel': 'X',
'ylabel':'Y',
'xlim':(-(2*np.pi),2*np.pi),
'ylim':(-(np.pi),np.pi),
'grid':True,
}
ax_plot_function.set(**props)
x=np.arange(-(2*np.pi),2*np.pi,0.01)
y=np.cos(x)
ax_plot_function.plot(x,y)
plt.show()
in Line29 happens an error that says
AttributeError: 'AxesSubplot' object has no property 'grid'
So I know that the function 'set()' can not have the attribute 'grid' in Line27,But how can I fix it and What attributes can I set exactly by using the function 'ax.set()'. Could I get a list of all attributes that can set by the function 'set()'? Or Please tell me where I can find the list.
Upvotes: 2
Views: 3149
Reputation: 30050
ax.set()
can set the properties defined in class matplotlib.axes.Axes.
There is also set_xxx()
api where xxx
is also the property in class matplotlib.axes.Axes.
The idea is simple, image you create a Python class and some properties. The related getter
and setter
method should be defined. Also, the constructor method can take initial values of those properties.
If you want to turn on the grid, use ax.grid(True)
.
Upvotes: 2