当前位置:   article > 正文

html中加pyecharts,pyecharts

html 嵌入pyecharts

柱状图

from pyecharts.charts import Bar

from pyecharts import options as opts

bar = Bar()

bar.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])

bar.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])

bar.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])

bar.set_global_opts(title_opts=opts.TitleOpts(title="某商场销售情况"))

# bar.reversal_axis() # 反转

bar.render_notebook()

356e024d49d7

image.png

折线图

x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

y_data = [820, 932, 901, 934, 1290, 1330, 1320]

from pyecharts.charts import Line

(

Line()

.set_global_opts(

tooltip_opts=opts.TooltipOpts(is_show=False),

xaxis_opts=opts.AxisOpts(type_="category"),

yaxis_opts=opts.AxisOpts(

type_="value",

axistick_opts=opts.AxisTickOpts(is_show=True),

splitline_opts=opts.SplitLineOpts(is_show=True),

),

)

.add_xaxis(xaxis_data=x_data)

.add_yaxis(

series_name="",

y_axis=y_data,

symbol="emptyCircle",

is_symbol_show=True,

label_opts=opts.LabelOpts(is_show=False),

)

.render_notebook()

)

356e024d49d7

image.png

柱状图反转

bar = Bar()

bar.add_xaxis(list(x))

bar.add_yaxis("嘿嘿",y,itemstyle_opts=opts.ItemStyleOpts(color='green'))

bar.reversal_axis() # 反转

bar.render_notebook()

356e024d49d7

image.png

实现几张图片拖拉拽

Page

from pyecharts.charts import Line,Page

from pyecharts import options as opts

f1 = Line()

f1.add_xaxis(list(x))

f1.add_yaxis('aa',y,is_smooth=True)

f1.set_global_opts(title_opts=opts.TitleOpts('哈哈哈'),

datazoom_opts=opts.DataZoomOpts(is_show=True), # 缩放

xaxis_opts=opts.AxisOpts(type_='value')) # 类型 :categary / value

f1.set_series_opts(label_opts=opts.LabelOpts(is_show=True))

f1.render_notebook()

f2 = Line()

f2.add_xaxis(list(x))

f2.add_yaxis('aa',y,is_smooth=True)

f2.set_global_opts(title_opts=opts.TitleOpts('哈哈2哈'),

datazoom_opts=opts.DataZoomOpts(is_show=True), # 缩放

xaxis_opts=opts.AxisOpts(type_='value')) # 类型 :categary / value

f2.set_series_opts(label_opts=opts.LabelOpts(is_show=True))

f2.render_notebook()

page = Page(layout=Page.DraggablePageLayout)

page.add(f1,f2)

page.render()

保存固定html

# 保存成固定html

page.save_resize_html('./render.html',cfg_file='./chart_config.json',dest='./new.html')

地图Geo

from pyecharts.charts import Geo

from pyecharts.faker import Faker

from pyecharts import options as opts

from pyecharts.globals import ChartType,SymbolType

go = Geo()

go.add_schema(maptype='china')

go.add('geo',[list(i) for i in zip(Faker.provinces,Faker.values())])

go.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

go.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True), # 显示左下角颜色控制

title_opts=opts.TitleOpts(title='示例'))

go.render_notebook()

356e024d49d7

image.png

[list(i) for i in zip(Faker.provinces,Faker.values())]

out:

[['广东', 60],

['北京', 65],

['上海', 64],

['江西', 104],

['湖南', 80],

['浙江', 107],

['江苏', 125]]

省级地图

g1 = Geo()

g1.add_schema(maptype='河南')

g1.add('geo',[['郑州',20],['新乡',30],['许昌',2800]])

g1.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

g1.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=3000), # 显示左下角颜色控制

title_opts=opts.TitleOpts(title='示例'))

g1.render_notebook()

356e024d49d7

image.png

直辖市地图

g2 = Geo()

g2.add_schema(maptype='北京')

g2.add('北京',[['昌平',20],['西城',30],['海淀',20],['通州区',233]])

g2.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

g2.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=300), # 显示左下角颜色控制

title_opts=opts.TitleOpts(title='示例嘿嘿'))

g2.render_notebook()

356e024d49d7

image.png

手动添加经纬度 自定义左下角单位

from pyecharts.globals import GeoType,ChartType

city = '杭州'

g3 = Geo()

g3.add_schema(maptype=city,is_roam=False)

# 手动添加经纬度

g3.add_coordinate('杭州师范',120.12321,30.2143432)

g3.add_coordinate('不懂大学',120.2712434,30.16233434)

data_pair = [['杭州师范',100],['不懂大学',500],['杭州',50]]

g3.add(' ',data_pair,symbol_size=20,type_=GeoType.EFFECT_SCATTER) # 涟漪效果 热图:ChartType.HEATMAP

# 左下角自定义

pieces = [

{'max':6,'label':'5一下','color':'pink'},

{'min':6,'max':10,'label':'5-10','color':'red'},

{'min':10,'max':100,'label':'10-100','color':'blue'}

]

g3.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=pieces),#,max_=800 # 显示左下角颜色控制

title_opts=opts.TitleOpts(title='示例嘿嘿'))

g3.render_notebook()

356e024d49d7

image.png

Map做图

Map与Geo的区别 Map可以是区域加颜色并显示名称

from pyecharts.charts import Map

g4 = Map()

# g4.add('嘿嘿',[list(z) for z in zip(Faker.provinces,Faker.values())],'china')

g4.add('嘿嘿',[['昌平区',200],['西城区',130],['海淀区',120],['通州区',133]],'北京')

g4.set_global_opts(title_opts=opts.TitleOpts(title='地图'),

visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=300))

g4.render_notebook()

356e024d49d7

image.png

隐藏Label

from pyecharts.charts import Map

g5 = Map()

# g4.add('嘿嘿',[list(z) for z in zip(Faker.provinces,Faker.values())],'china')

g5.add('北京',[['昌平区',200],['西城区',130],['海淀区',120],['通州区',133]],'北京',is_map_symbol_show=False) #is_map_symbol_show不出现点

g5.set_global_opts(title_opts=opts.TitleOpts(title='地图'),

visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=300))

g5.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) # label_opts隐藏Label, is_show=True

g5.render_notebook()

356e024d49d7

image.png

渐变图

数据

d = [['密云区', 2],

['延庆区', 1],

['朝阳区', 3],

['丰台区', 4],

['石景山区', 5],

['海淀区', 6],

['门头沟区', 6],

['房山区', 5],

['通州区', 4],

['顺义区', 3],

['昌平区', 2],

['大兴区', 1],

['怀柔区', 1],

['平谷区', 2],

['东城区', 3],

['西城区', 4]]

自定义

pieces2 = [

{"min":6 ,'max':6,"label": '增速大占比小',"color": '#070093'},

{"min":5 ,"max":5 ,"label": '占比小增速大','color':'#1c3fbf'},

{"min":4 , "max":4 ,"label": '占比小增速小','color':'#1482e5'},

{"min":3, "max":3,"label": '占比大增速大','color':'#70b4eb'},

{"min":2, "max":2,"label": '占比大增速大','color':'#b4e0f3'},

{"min":1, "max":1, "label": '占比中增速中',"color": '#ffffff'}, #DDFFFF

]

# ["#070093", "#1c3fbf", "#1482e5", "#70b4eb", "#b4e0f3", "#ffffff"];

代码

g5 = Map()

g5.add('北极',d,'北京',is_map_symbol_show=False) #is_map_symbol_show不出现点

g5.set_global_opts(title_opts=opts.TitleOpts(title='嘿嘿

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/165069
推荐阅读
相关标签