如何在python中使用ggplot畫圖?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
簡介:
ggplot類是在plotnine中的,能夠生成一個圖形。
pip install pandas plotnine
csv文件加載到survs_df的數(shù)據(jù)框架:
ggplot(survs_df, aes(x='weight', y='hindfoot_length', size = 'year')) + geom_point()
1、設(shè)置數(shù)據(jù)框
2、需要將數(shù)據(jù)框架轉(zhuǎn)換成位置、顏色、大小等
3、顯示實際圖形元素
實例代碼:
(ggplot(mtcars, aes(‘wt', ‘mpg', color='factor(cyl)')) + geom_point() + labs(title='Miles per gallon vs Weight', x='Weight', y='Miles per gallon') + guides(color=guide_legend(title='Number of Cylinders')) )
輸出效果:
知識點擴(kuò)展:
繪制散點圖,geom_point()
讀取外部數(shù)據(jù)進(jìn)行繪圖
>>> import pandas as pd >>> from ggplot import * >>> df=pd.read_table('C:\Users\lenovo\Desktop\mtcars.txt') >>> df ··name type number volume size other 0 td T 96 3 20 c 1 sf F 87 5 65 c 2 cc F 79 9 80 d
如果讀取的數(shù)據(jù)沒有column可以添加
df.columns=['name','type','number','volume','size','other'] >>> p=ggplot(df, aes(x='number', y='volume', size='factor(size)', color='factor(other)'))+geom_point() >>> print p
關(guān)于如何在python中使用ggplot畫圖問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
網(wǎng)站名稱:如何在python中使用ggplot畫圖-創(chuàng)新互聯(lián)
文章地址:http://www.chinadenli.net/article20/dsojco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、ChatGPT、品牌網(wǎng)站制作、網(wǎng)站營銷、面包屑導(dǎo)航、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容