【python 数据可视化】美丽漂亮的画图神器--pyecharts
程序员文章站
2022-06-06 08:04:24
...
今天我们介绍下pyechats 的用法和一个简单的例子。
安装:
pip install pyecharts
步骤1:导入相关包:
# 导入包
import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.globals import *
from pyecharts.faker import *
# 读取数据
data=pd.read_csv('D:/机器学习/air_quality.csv',sep=',')
fun1=lambda x:x.split('-')[0]
fun2=lambda x:x.split('-')[1]
data['year']=data['record_date'].apply(fun1)
data['month']=data['record_date'].apply(fun2)
# 成都空气质量的玫瑰花饼图
df1=data.groupby(['city_name','quality_level'], as_index=False).count()
df1=df1[df1['city_name']=='成都']
x = list(df1['quality_level'])
y = list(df1['so2_val'])
pie = Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
pie.add("",[list(z) for z in zip(x, y)],radius=["50%", "75%"],center=["45%", "60%"],rosetype="radius",)
# pie.set_colors(["blue", "green", "yellow", "red", "pink", "orange"])
pie.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
pie.set_global_opts(title_opts=opts.TitleOpts(title="成都空气质量玫瑰花饼图",pos_left="32%"),
legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="5%"))
pie.render_notebook()
# pie.render(data_path+'成都空气质量饼图.html')
更多用法请看官方文档:
pyecharts官方文档
上一篇: php调用自各儿的java(转)