[Matplotlib] Usage of DataFrame.plot()-Subgraph Editing

A detailed explanation of the parameters of the DataFrame.plot() function has been introduced by many bloggers, for example: https://blog.csdn.net/h_hxx/article/details/90635650

However, it is difficult to edit the sub-figure parameters in the DataFrame.plot() function. How should the font and font size of the legend and coordinates of the sub-figure be modified?

After various searches and studies, I found a method that is easier to understand and implement:

  •  DataFrame.plot() parameter drawing, the font is very small:
month.plot(subplots=True,style='k.-',markersize = 15,markeredgecolor = 'r',markerfacecolor = 'r',
                figsize=(20,40),grid=True,ylim=[0,40],ylabel="PM2.5(1μg/m^3)",xlabel="Date"  )
plt.show()

  •  DataFrame.plot() draws the graph with parameters, and edits the coordinate scale, coordinate name, font and font size of the legend:
font3 = {'family' : 'Times New Roman','weight' : 'normal','size' : 20,}

# DataFrame.plot(fontsize=15)定义坐标刻度的字号
fig = month.plot(subplots=True,style='k.-',markersize = 15,markeredgecolor = 'r',markerfacecolor = 'r',
                figsize=(20,40),grid=True,ylim=[0,40],fontsize=15 )

# 定义坐标名称、图例的字体字号
for i in range(2):
    fig[i].set_ylabel("PM2.5(1μg/m^3)",font3)
    fig[i].set_xlabel("Date" ,font3)
    fig[i].legend(fontsize=20)

# 定义图标题
plt.title('PM2.5 of Tokyo',font3,y=14.3)

plt.show()

Here, the problem is solved.

Note:

The key to solving the problem is the use of fig=dataframe.plot(), so what is fig?

print(fig)
[<matplotlib.axes._subplots.AxesSubplot object at 0x0000021AA3B78D68>
 <matplotlib.axes._subplots.AxesSubplot object at 0x0000021AA4028550>]

The output is an ndarray array, what does it mean, see: https://blog.csdn.net/u012762410/article/details/78968708

Guess you like

Origin blog.csdn.net/weixin_43217427/article/details/108772172