陳冠君 陳冠君 - 1 year ago 64
Python Question

I can't understand why "ax=ax" meaning in matplotlib

from datetime import datetime
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
data=pd.read_csv(r"C:\Users\champion\Desktop\ch02\spx.csv")
spx=data["SPX"]
spx.plot(**ax=ax**,style="k-")


I can't understand why "ax=ax" meaning in matplotlib.

Answer Source

From the documentation of plot():

DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, sharex=None, sharey=False, layout=None, figsize=None, use_index=True, title=None, grid=None, legend=True, style=None, logx=False, logy=False, loglog=False, xticks=None, yticks=None, xlim=None, ylim=None, rot=None, fontsize=None, colormap=None, table=False, yerr=None, xerr=None, secondary_y=False, sort_columns=False, **kwds)

Parameters: ax : matplotlib axes object, default None

You can see that ax is a keyword argument here. It just happens that you also named your variable as ax and you are sending it as the value of that keyword argument to the function plot().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download