Python的绘图库也允许用户创建优雅的图形,本章给大家介绍的是关于ggplot绘制画图的技巧,ggplot2建立在grid系统上,这个系统不支持纹理。需要额外创建一堆数据,再基于这些数据构建一个geom_path图层,盖在柱图上才可以进行各种绘制,下面给大家详细讲解下怎么使用ggplot绘图。
简介:
ggplot类是在plotnine中的,能够生成一个图形。
安装:
pip install pandas plotnine
csv文件加载到survs_df的数据框架:
ggplot(survs_df, aes(x='weight', y='hindfoot_length', size = 'year')) + geom_point()
生成图形步骤:
1、设置数据框
2、需要将数据框架转换成位置、颜色、大小等
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')) )
输出效果:
知识点扩展:
绘制散点图,geom_point()
读取外部数据进行绘图
> 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
如果读取的数据没有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
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]