from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.globals import ThemeType # 主题颜色
from pyecharts.charts import Bar # 实例化
# 改变皮肤, 尺寸
bar = Bar(init_opts=opts.InitOpts(
theme=ThemeType.DARK,
width='800px',
height="600px"))
bar.add_xaxis(Faker.days_attrs)
bar.add_yaxis("商家A",Faker.days_values)
bar.set_global_opts(
title_opts=opts.TitleOpts(
title="Bar_基本示例",
subtitle="我是副标题"),
# 添加窗口滑块效果
datazoom_opts=[opts.DataZoomOpts()]
)
bar.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
3D柱状图
import random
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import Bar3D # 实例化
bar3d = Bar3D()
# 需要三维的数据 ,
data = [(i,j,random.randint(0,12)) for i in range(24) for j in range(6)]
bar3d.add(
"",
data,
xaxis3d_opts=opts.Axis3DOpts(Faker.clock,type_='category'),
yaxis3d_opts=opts.Axis3DOpts(Faker.week_en,type_='category'),
zaxis3d_opts=opts.Axis3DOpts(type_='value'),
)
bar3d.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=20),
title_opts=opts.TitleOpts(title="Bar3D_基本示例")
)
bar3d.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
折线 / 面积图
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import Line # 实例化
line = Line()
line.add_xaxis(Faker.choose())
# is_smooth 折现变平滑
line.add_yaxis("商家A",Faker.values(),
is_smooth=True,
areastyle_opts=opts.AreaStyleOpts(
# opacity 透明度
opacity=0.2,
# color 填充区域颜色
color='#000'
))
line.add_yaxis("商家B",Faker.values())
line.set_global_opts(title_opts=opts.TitleOpts(title='Line_基本示例'))
line.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
饼图
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import Pie # 实例化
pie = Pie()
# radius 内环和外环半径, 列表类型
# rosetype 玫瑰饼图
# resetype = 'area' , 所有扇区圆心角相同, 仅通过半径展现圆心角大小
# = 'radius' , 圆心角展现百分比 ,
pie.add("",[list(z) for z in zip(Faker.choose(),Faker.values())],
radius=["40%","75%"],
rosetype='radius')
pie.set_global_opts(title_opts=opts.TitleOpts(title='Pie_基本示例'))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))
pie.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
涟漪效果散点图
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import EffectScatter # 实例化
from pyecharts.globals import SymbolType
effect_scatter = EffectScatter()
effect_scatter.add_xaxis(Faker.choose())
effect_scatter.add_yaxis("",
Faker.values(),
symbol=SymbolType.ARROW)
effect_scatter.set_global_opts(title_opts=opts.TitleOpts(title="EffectScatter_基本示例"))
effect_scatter.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
漏斗图
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import Funnel # 实例化
funnel = Funnel()
funnel.add(
"用户转化率",
[list(z) for z in zip(Faker.choose(),Faker.values())],
# position = 'inside' 图例名放在图形中间
label_opts=opts.LabelOpts(position='inside')
)
funnel.set_global_opts(title_opts=opts.TitleOpts(title="Funnel_基本示例"))
funnel.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
地理坐标系
from pyecharts.faker import Faker # 数据集
from pyecharts import options as opts # 配置
from pyecharts.charts import Geo # 实例化
geo = Geo()
geo.add_schema(maptype="china")
geo.add('geo',[list(z) for z in zip(Faker.provinces,Faker.values())],
type_='heatmap')
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="Geo_基本示例")
)
geo.render(R'F:\1000篇技术博客\pyecharts\chart1.html')
水球图
from pyecharts import options as opts # 配置
from pyecharts.charts import Liquid # 实例化
liquid = Liquid()
liquid.add('Liquid',[0.7,0.6,0.5])
liquid.set_global_opts(title_opts=opts.TitleOpts(title="Liquid_基本示例"))
liquid.render(R'F:\1000篇技术博客\pyecharts\chart1.html')