1
當我運行該功能,爲什麼兩個數字對象出現而不是一個?
def plot_data(df, title="", xlabel="", ylabel="", figsize=(12, 8), save_figure=False):
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('small')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.legend(bbox_to_anchor=(1,1), loc='upper left', prop=fontP)
plt.grid()
df.plot()
plt.show()
if save_figure:
plt.savefig(title)
的結果是這樣的:
我不明白爲什麼是兩個圖形對象上來。它看起來像legend
,grid
沒有適當適用...
此外,我想清楚地知道「圖形對象創建時」或「我怎樣才能創建一個沒有混淆的圖形對象」的東西。有沒有什麼好的教程?
我覺得最後一段有點太廣,特別是如果你混合'matplotlib'和' pandas'。有一些matplotlib教程(即https://matplotlib.org/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes是一個很好的起點),但它們與'pandas'直接相關的方式更多複雜。 – MSeifert