假设你获取到了某年内地电影票房前20的电影(列表a)和电影票房数据(列表b),那么如何更加直观的展示该数据?
a = [“战狼2”,“速度与激情8”,“功夫瑜伽”,“西游伏妖篇”,“变形金刚5:最后的骑士”,“摔跤吧!爸爸”,
“加勒比海盗5:死无对证”,“金刚:骷髅岛”,“极限特工:终极回归”, “侠:英雄归来”,“悟空传”,“银河护卫队2”,“情圣”,“新木乃伊”,]
b=[56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,
10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23] 单位:亿
from pyecharts import Bar
movieName = ["战狼2","速度","功夫瑜伽","西游伏妖篇","变形金刚5","摔跤吧"]
movieMoney = [56.01, 26.94, 17.53, 16.49, 15.45, 12.96]
print(len(movieName), len(movieMoney))
bar = Bar(title="某年内地电影票房前20的电影", subtitle="这是一个子标题")
# 添加图表的数据, 或者配置信息
bar.add("电影信息",movieName, movieMoney)
# 默认情况下会生成一个render.html文件
bar.render()
from pyecharts import Bar
x_movies_name = ["猩球崛起", "敦刻尔克", "蜘蛛侠", "战狼2"]
y_16 = [15746, 312, 4497, 319]
y_15 = [12357, 156, 2045, 168]
y_14 = [2358, 399, 2358, 362]
bar = Bar(title="某年内地电影票房前20的电影", subtitle="子标题")
bar.add('14号',x_movies_name,y_14)
bar.add('15号',x_movies_name,y_15)
bar.add('16号',x_movies_name,y_16)
bar.render()
from pyecharts import EffectScatter
x_march = list(range(1, 32))
y_temp_march = [11, 17, 16, 11, 12, 11, 12, 6, 6, 7, 8, 9, 12, 15, 14, 17, 18, 21, 16, 17, 20, 14, 15, 15, 15, 19, 21,
22, 22, 22, 23]
es=EffectScatter(title='3、4月份气温变化的散点图',subtitle='子标题')
es.add('三月',x_march,y_temp_march,symbol_size=5,line_color='red')
es.add('四月',x_march,y_temp_march,symbol_size=8,line_color='green')
es.render()
from pyecharts import Funnel
fun=Funnel('漏斗图')
x_movies_name = ["猩球崛起", "敦刻尔克", "蜘蛛侠", "战狼2"]
y_16 = [20, 40, 60, 80]
fun.add('电影票房',x_movies_name,y_16)
fun.render()
from pyecharts import Gauge
ga=Gauge('仪表盘图')
ga.add('cpu','cpu使用率',87)
ga.render()
from pyecharts import Liquid
li=Liquid('水球图')
# 接收的数据必须是一个列表或元组,可通过shape更改形状
li.add('cpu占用率',[0.6,0.13,0.5,0.2],shape='diamond')
li.render()
from pyecharts import Pie
attr=['男','女','其他']
values=[60,38,2]
pie=Pie('饼状图')
# is_label_show:是否显示各个参数的占比
pie.add('性别占比',attr,values,is_label_show=True)
pie.render()
import random
from pyecharts import Line
x=list(range(30))
y_mar=[random.randint(20,38) for i in range(30)]
y_oct=[random.randint(20,38) for i in range(30)]
line=Line('折线图')
# 标记点或线必须是一个列表
line.add('三月',x,y_mar,mark_line=['max'],mark_point=['min'])
line.add('十月',x,y_oct,mark_line=['min'],mark_point=['max'])
line.render()
import random
from pyecharts import Line
x=list(range(30))
y_mar=[random.randint(20,38) for i in range(30)]
y_oct=[random.randint(20,38) for i in range(30)]
line=Line('折线图')
# 标记点或线必须是一个列表
line.add('三月',x,y_mar,mark_line=['max'],mark_point=['min'],is_step=True)
line.add('十月',x,y_oct,mark_line=['min'],mark_point=['max'],is_step=True)
line.render()
import random
from pyecharts import Line
x=list(range(30))
y_mar=[random.randint(20,38) for i in range(30)]
y_oct=[random.randint(20,38) for i in range(30)]
line=Line('折线图')
# 标记点或线必须是一个列表
line.add('三月',x,y_mar,is_fill=True,area_color='red',area_opacity=0.5)
line.add('十月',x,y_oct,is_fill=True,area_color='green',area_opacity=0.3)
line.render()
from pyecharts import Geo
data = [
("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15),
("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21),
("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25),
("文登", 25),("上海", 25),("攀枝花", 25),("威海", 25),("承德", 25),("厦门", 26),
("汕尾", 26),("潮州", 26),("丹东", 27),("太仓", 27),("曲靖", 27),("烟台", 28),
("福州", 29),("瓦房店", 30),("即墨", 30),("抚顺", 31),("玉溪", 31),("张家口", 31),
("阳泉", 31),("莱州", 32),("湖州", 32),("汕头", 32),("昆山", 33),("宁波", 33),
("湛江", 33),("揭阳", 34),("荣成", 34),("连云港", 35),("葫芦岛", 35),("常熟", 36),
("东莞", 36),("河源", 36),("淮安", 36),("泰州", 36),("南宁", 37),("营口", 37),
("惠州", 37),("江阴", 37),("蓬莱", 37),("韶关", 38),("嘉峪关", 38),("广州", 38),
("延安", 38),("太原", 39),("清远", 39),("中山", 39),("昆明", 39),("寿光", 40),
("盘锦", 40),("长治", 41),("深圳", 41),("珠海", 42),("宿迁", 43),("咸阳", 43),
("铜川", 44),("平度", 44),("佛山", 44),("海口", 44),("江门", 45),("章丘", 45),
("肇庆", 46),("大连", 47),("临汾", 47),("吴江", 47),("石嘴山", 49),("沈阳", 50),
("苏州", 50),("茂名", 50),("嘉兴", 51),("长春", 51),("胶州", 52),("银川", 52),
("张家港", 52),("三门峡", 53),("锦州", 54),("南昌", 54),("柳州", 54),("三亚", 54),
("自贡", 56),("吉林", 56),("阳江", 57),("泸州", 57),("西宁", 57),("宜宾", 58),
("呼和浩特", 58),("成都", 58),("大同", 58),("镇江", 59),("桂林", 59),("张家界", 59),
("宜兴", 59),("北海", 60),("西安", 61),("金坛", 62),("东营", 62),("牡丹江", 63),
("遵义", 63),("绍兴", 63),("扬州", 64),("常州", 64),("潍坊", 65),("重庆", 66),
("台州", 67),("南京", 67),("滨州", 70),("贵阳", 71),("无锡", 71),("本溪", 71),
("克拉玛依", 72),("渭南", 72),("马鞍山", 72),("宝鸡", 72),("焦作", 75),("句容", 75),
("北京", 79),("徐州", 79),("衡水", 80),("包头", 80),("绵阳", 80),("乌鲁木齐", 84),
("枣庄", 84),("杭州", 84),("淄博", 85),("鞍山", 86),("溧阳", 86),("库尔勒", 86),
("安阳", 90),("开封", 90),("济南", 92),("德阳", 93),("温州", 95),("九江", 96),
("邯郸", 98),("临安", 99),("兰州", 99),("沧州", 100),("临沂", 103),("南充", 104),
("天津", 105),("富阳", 106),("泰安", 112),("诸暨", 112),("郑州", 113),("哈尔滨", 114),
("聊城", 116),("芜湖", 117),("唐山", 119),("平顶山", 119),("邢台", 119),("德州", 120),
("济宁", 120),("荆州", 127),("宜昌", 130),("义乌", 132),("丽水", 133),("洛阳", 134),
("秦皇岛", 136),("株洲", 143),("石家庄", 147),("莱芜", 148),("常德", 152),("保定", 153),
("湘潭", 154),("金华", 157),("岳阳", 169),("长沙", 175),("衢州", 177),("廊坊", 193),
("菏泽", 194),("合肥", 229),("武汉", 273),("大庆", 279)]
geo = Geo(
"全国主要城市空气质量",
"data from pm2.5",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
attr, value = geo.cast(data)
geo.add(
"",
attr,
value,
visual_range=[0, 200],
visual_text_color="#fff",
symbol_size=15,
is_visualmap=True,
)
geo.render()
from pyecharts import Map
import numpy as np
value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
attr = [
"福建", "山东", "北京", "上海", "甘肃", "新疆", "河南", "广西", "西藏"
]
# background_color="#404a59"
map = Map("Map 结合 VisualMap 示例", width=1200, height=600, )
map.add(
"",
attr,
value,
maptype="china",
is_visualmap=True,
visual_text_color="#000",
)
map.render()