pyecharts的基本使用
Posted 是璇子鸭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyecharts的基本使用相关的知识,希望对你有一定的参考价值。
官网链接
示例
from pyecharts.charts import Bar
from pyecharts import options as opts
# 内置主题类型可查看 pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [15, 6, 45, 20, 35, 66])
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
#设置全局配置
.set_global_opts(
title_opts=opts.TitleOpts(title='商家AB销售额对比'),
legend_opts =opts.LegendOpts(is_show=True),
toolbox_opts =opts.ToolboxOpts(is_show=True),
visualmap_opts=opts.VisualMapOpts(is_show=True),
tooltip_opts =opts.DataZoomOpts(is_show=True)
)
)
bar.render('haha.html')
疫情数据显示
Bar - Finance_indices_2002
https://gallery.pyecharts.org/#/Bar/finance_indices_2002
- 全局配置项标注的需要掌握
- 系列配置项
- ctrl+f快速搜索
深圳各区均价
import pandas as pd
from pyecharts.globals import ThemeType
# 1.读取数据
df = pd.read_csv(r'C:\\Users\\JSJSYS\\PycharmProjects\\untitled\\python实战\\lianjia_data.csv')
# 2根据地区分组,求unit_price均值
temp = df.groupby('area')['unit_price'].mean().reset_index()
# dataframe迭代遍历*****
result = []
for index,value in temp.iterrows():
# index每行数据索引
# value每行数据对应Series,其索引为列名
#print(value['area'],value['unit_price'])
result.append([value['area'],round(value['unit_price']/10000,1)])
print(result)
result2 = [[value['area'],
round(value['unit_price']/10000,1)
]
for index,value in temp.iterrows()
]
from pyecharts import options as opts
from pyecharts.charts import Map
c = (
Map(init_opts=opts.InitOpts(theme=ThemeType.DARK))
# 地图类型,具体参考 pyecharts.datasets.map_filenames.json 文件
.add("深圳各区均价", result2, "深圳")
.set_global_opts(
title_opts=opts.TitleOpts(title="Map-深圳地图"),
visualmap_opts=opts.VisualMapOpts(max_=10)
)
.render("11-深圳各区均价.html")
房价面积散点图
import pandas as pd
#1. 读取数据
df = pd.read_csv(r'C:\\Users\\JSJSYS\\PycharmProjects\\untitled\\python实战\\lianjia_data.csv')
#2 散点图
from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.globals import ThemeType
c = (
Scatter(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add_xaxis(df['houseSize']) #面积
.add_yaxis("房价-面积散点图", df['total_price']) #房价(人们的侧重)
.set_global_opts(
title_opts=opts.TitleOpts(title="房价-面积散点图"),
visualmap_opts=opts.VisualMapOpts(max_=150),
)
.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
# 标记点
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(name="最低廉的房子", type_="min"),
opts.MarkPointItem(name="最奢华的房子", type_="max")
]
)
)
.render("scatter_visualmap_color.html")
)
以上是关于pyecharts的基本使用的主要内容,如果未能解决你的问题,请参考以下文章