dataframe進行groupby後畫圖座標軸刻度問題

首先看我們要用到的畫圖函數:

DataFrame.plot(x=Noney=Nonekind='line'ax=Nonesubplots=Falsesharex=None,sharey=Falselayout=Nonefigsize=Noneuse_index=Truetitle=Nonegrid=None,legend=Truestyle=Nonelogx=Falselogy=Falseloglog=Falsexticks=Noneyticks=None,xlim=Noneylim=Nonerot=Nonefontsize=Nonecolormap=Nonetable=Falseyerr=None,xerr=Nonesecondary_y=Falsesort_columns=False**kwds)

參數具體分析:https://yiyibooks.cn/dongyongping1015/pandas_0220/html/generated/pandas.DataFrame.plot.html#pandas.DataFrame.plot

當然還有其他常用操作今天主要以這個爲例。https://mp.csdn.net/postedit/83993002

以西瓜數據集爲例進行代碼分析:

wmdf = pd.read_csv('watermelon3_0.csv')
wmdf.describe()
	num	density	sugar
count	17.000000	17.000000	17.000000
mean	9.000000	0.532647	0.212824
std	5.049752	0.166906	0.119879
min	1.000000	0.243000	0.042000
25%	5.000000	0.403000	0.103000
50%	9.000000	0.593000	0.211000
75%	13.000000	0.657000	0.267000
max	17.000000	0.774000	0.460000

對上面的統計分析進行畫圖:

wmdf.describe().plot(title = 'analysis')

 

但是橫座標並沒有標出刻度,我們看函數定義中的參數:

use_index=True,就是使用index作爲x軸的刻度。

但是爲什麼還是沒有畫出來呢?原來還有另一個參數,xticks=None,把這個參數設置如下

wmdf.describe().plot(title = 'analysis',xticks = range(0,9))

 此時終於有了刻度,如果我們不希望用index做刻度,只需要將use_index參數設置爲False即可。

wmdf.describe().plot(use_index = False, title = 'analysis',xticks = range(0,9))

這裏是我自己編程時遇到的,大家有其他的歡迎補充! 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章