def WorldMap(): namemap = {"阿富汗": "Afghanistan", "安哥拉": "Angola", "阿尔巴尼亚": "Albania", "阿尔及利亚": "Algeria", "阿根廷": "Argentina", "亚美尼亚": "Armenia", "澳大利亚": "Australia", "奥地利": "Austria", "阿塞拜疆": "Azerbaijan", "巴哈马": " Bahamas ", "孟加拉国": "Bangladesh", "比利时": " Belgium ", "贝宁": "Benin", "布基纳法索": "Burkina Faso", "布隆迪": " Burundi", "保加利亚": "Bulgaria", "波斯尼亚和黑塞哥维那": "Bosnia and Herz", "白俄罗斯": "Belarus", "伯利兹": "Belize", "百慕大群岛": "Bermuda", "玻利维亚": "Bolivia", "巴西": "Brazil", "文莱": "Brunei ", "不丹": "Bhutan", "博茨瓦纳": "Botswana", "柬埔寨": "Cambodia", "喀麦隆": "Cameroon", "加拿大": "Canada", "中非共和国": "Central African Rep.", "乍得": "Chad", "智利": "Chile", "中国": "China", "哥伦比亚": "Colombia", "刚果(金)": "Congo", "哥斯达黎加": "Costa Rica", "科特迪瓦": "Côte d'Ivoire", "克罗地亚": "Croatia ", "古巴": "Cuba", "塞浦路斯": "Cyprus", "捷克共和国": "CzechRep", "韩国": "Dem.Rep.Korea", "刚果(布)": "Dem. Rep. Congo", "丹麦": "Denmark", "吉布提": "Djibouti", "多米尼加": "Dominican Rep.", "厄瓜多尔": "Ecuador", "埃及": "Egypt", "萨尔瓦多": "ElSalvador", "赤道几内亚": "Eq.Guinea", "厄立特里亚": "Eritrea", "爱沙尼亚": "Estonia", "埃塞俄比亚": "Ethiopia", "福克兰群岛": "FalklandIs", "斐济": "Fiji", "芬兰": "Finland", "法国": "France", "法属圭亚那": "FrenchGuiana", "法属南部领地": "Fr.S.AntarcticLands", "加蓬": "Gabon", "冈比亚": "Gambia", "德国": "Germany", "佐治亚州": "Georgia ", "加纳": "Ghana", "希腊": "Greece", "格陵兰": "Greenland", "危地马拉": "Guatemala", "几内亚": "Guinea", "几内亚比绍": "Guinea-Bissau", "圭亚那": "Guyana", "海地": "Haiti", "赫德岛和麦克唐纳群岛": "HeardI.andMcDonaldIs", "洪都拉斯": "Honduras", "匈牙利": "Hungary", "冰岛": "Iceland", "印度": "India", "印度尼西亚": "Indonesia", "伊朗": "Iran", "伊拉克": "Iraq", "爱尔兰": "Ireland", "以色列": "Israel", "意大利": "Italy", "象牙海岸": "IvoryCoast", "牙买加": "Jamaica", "日本": "Japan", "乔丹": "Jordan", "克什米尔": "Kashmir", "哈萨克斯坦": "Kazakhstan", "肯尼亚": "Kenya", "科索沃": "Kosovo", "科威特": "Kuwait", "吉尔吉斯斯坦": "Kyrgyzstan", "老挝": "Lao PDR", "拉脱维亚": "Latvia", "黎巴嫩": "Lebanon", "莱索托": "Lesotho", "利比里亚": "Liberia", "利比亚": "Libya", "立陶宛": "Lithuania", "卢森堡": "Luxembourg", "马达加斯加": "Madagascar", "马其顿": "Macedonia", "马拉维": "Malawi", "马来西亚": "Malaysia", "马里": "Mali", "毛里塔尼亚": "Mauritania", "墨西哥": "Mexico", "摩尔多瓦": "Moldova", "蒙古": "Mongolia", "黑山": "Montenegro", "摩洛哥": "Morocco", "莫桑比克": "Mozambique", "缅甸": "Myanmar", "纳米比亚": "Namibia", "荷兰": "Netherlands", "新喀里多尼亚": "New Caledonia", "新西兰": "New Zealand", "尼泊尔": "Nepal", "尼加拉瓜": "Nicaragua", "尼日尔": "Niger", "尼日利亚": "Nigeria", "朝鲜": "Korea", "北塞浦路斯": "NorthernCyprus", "挪威": "Norway", "阿曼": "Oman", "巴基斯坦": "Pakistan", "巴拿马": "Panama", "巴布亚新几内亚": "Papua New Guinea", "巴拉圭": "Paraguay", "秘鲁": "Peru", "刚果": "Republi cofthe Congo", "菲律宾": "Philippines", "波兰": "Poland", "葡萄牙": "Portugal", "波多黎各": "Puerto Rico", "卡塔尔": "Qatar", "塞尔维亚共和国": "RepublicofSerbia", "罗马尼亚": "Romania", "俄罗斯": "Russia", "卢旺达": "Rwanda", "萨摩亚": "Samoa", "沙特阿拉伯": "Saudi Arabia", "塞内加尔": "Senegal", "塞尔维亚": "Serbia", "塞拉利昂": "Sierra Leone", "斯洛伐克": "Slovakia", "斯洛文尼亚": "Slovenia", "所罗门群岛": "SolomonIs", "索马里兰": "Somaliland", "索马里": "Somalia", "南非": "South Africa", "南乔治亚和南桑德威奇群岛": "S.Geo.andS.Sandw.Is", "南苏丹": "S.Sudan", "西班牙": "Spain", "斯里兰卡": "Sri Lanka", "苏丹": "Sudan", "苏里南": "Suriname", "斯威士兰": "Swaziland", "瑞典": "Sweden", "瑞士": "Switzerland", "叙利亚": "Syria", "塔吉克斯坦": "Tajikistan", "坦桑尼亚": "Tanzania", "泰国": "Thailand", "东帝汶": "Timor-Leste", "多哥": "Togo", "特立尼达和多巴哥": "TrinidadandTobago", "突尼斯": "Tunisia", "土耳其": "Turkey", "土库曼斯坦": "Turkmenistan", "乌干达": "Uganda", "乌克兰": "Ukraine", "沙特阿拉伯": "United Arab Emirates", "大不列颠联合王国": "United Kingdom", "坦桑尼亚联合共和国": "UnitedRepublicofTanzania", "美国": "United States", "美利坚合众国": "UnitedStatesofAmerica", "乌拉圭": "Uruguay", "乌兹别克斯坦": "Uzbekistan", "瓦努阿图": "Vanuatu", "委内瑞拉": "Venezuela", "越南": "Vietnam", "西岸": "WestBank", "西撒哈拉": "W.Sahara", "也门共和国": "Yemen", "赞比亚共和国": "Zambia", "津巴布韦": "Zimbabwe"} url = 'http://api.tianapi.com/txapi/ncovabroad/index?key=0fd7df4315148dc405068de771dc279e' data_world = requests.get(url).json() oversea_confirm = [] for item in data_world['newslist']: try: country = namemap[item['provinceName']] except: country = 'United Kingdom' oversea_confirm.append((country.replace('United States of America', 'United States'), item['confirmedCount'])) world_map = ( Map() .add('累计确诊人数', oversea_confirm, 'world', is_map_symbol_show=False, is_roam=False) .set_series_opts(label_opts=opts.LabelOpts(is_show=False, color='#fff')) .set_global_opts( title_opts=opts.TitleOpts(title='全球疫情累计确诊人数地图'), legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=2700, is_piecewise=True, pieces=[ {"max":999999999,"min":1000000,"label":"1000000人以上", "color":"#000000"}, {"max": 999999, "min": 100000, "label": "100000-999999人", "color": "#8A0808"}, {"max": 99999, "min": 10000, "label": "10000-99999人", "color": "#B40404"}, {"max": 9999, "min": 1000, "label": "1000-9999人", "color": "#DF0101"}, {"max": 999, "min": 500, "label": "500-999人", "color": "#F78181"}, {"max": 499, "min": 100, "label": "100-499人", "color": "#F5A9A9"}, {"max": 99, "min": 10, "label": "10-99人", "color": "#FFFFCC"}, ]) ) ) return world_map
.add( "", data_pair=data, highlight_policy="ancestor", radius=[0, "95%"], sort_="null", levels=[ {}, { "r0": "15%", "r": "35%", "itemStyle": {"borderWidth": 2}, "label": {"rotate": "tangential"}, }, {"r0": "35%", "r": "70%", "label": {"align": "right"}}, { "r0": "70%", "r": "72%", "label": {"position": "outside", "padding": 3, "silent": False}, "itemStyle": {"borderWidth": 3}, }, ], ) .set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-官方示例")) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}")) ) c.width = "100%" put_html(c.render_notebook())
def render_lines(country_name): #------------------------------------------------------------------------------------- # 第一步:读取数据 #------------------------------------------------------------------------------------- n = "dataSets/countrydata.csv" data = pd.read_csv(n) data = data[data['countryName'] == country_name] date_list = list(data['dateId']) date_list = list(map(lambda x: str(x), date_list)) confirm_list = list(data['confirmedCount']) current_list = list(data['currentConfirmedCount']) dead_list = list(data['deadCount']) heal_list = list(data['curedCount']) print(len(date_list)) #print(date_list) # 日期 #print(confirm_list) # 确诊数据 #print(current_list) # 疑似数据 #print(dead_list) # 死亡数据 #print(heal_list) # 治愈数据 #------------------------------------------------------------------------------------- # 第二步:绘制折线面积图 #------------------------------------------------------------------------------------- line = ( Line().add_xaxis(date_list) # 平均线 最大值 最小值 .add_yaxis('确诊数据', confirm_list, is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max"), opts.MarkPointItem(type_="min") ])).add_yaxis( '现存确诊数据', current_list, is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max"), opts.MarkPointItem(type_="min") ])).add_yaxis( '死亡数据', dead_list, is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max"), opts.MarkPointItem(type_="min") ])).add_yaxis( '治愈数据', heal_list, is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max"), opts.MarkPointItem(type_="min") ])) # 隐藏数字 设置面积 .set_series_opts(areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False)) # 设置x轴标签旋转角度 .set_global_opts(xaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(rotate=-30)), yaxis_opts=opts.AxisOpts(name='人数', min_=3), title_opts=opts.TitleOpts(title='2019-nCoV' + country_name + '疫情数据曲线图'))) return line
from pyecharts import options as opts from pyecharts.charts import Scatter from pyecharts.commons.utils import JsCode from pyecharts.faker import Faker c = (Scatter().add_xaxis(Faker.choose()).add_yaxis( "商家A", [list(z) for z in zip(Faker.values(), Faker.choose())], label_opts=opts.LabelOpts(formatter=JsCode( "function(params){return params.value[1] +' : '+ params.value[2];}")), ).set_global_opts( title_opts=opts.TitleOpts(title="Scatter-多维度数据"), tooltip_opts=opts.TooltipOpts(formatter=JsCode( "function (params) {return params.name + ' : ' + params.value[2];}")), visualmap_opts=opts.VisualMapOpts(type_="color", max_=150, min_=20, dimension=1), ).render("Scatter_multi_dimension.html"))
def image_host_resource(doc_path, hosts_metrics, host): options = opts.InitOpts(js_host=os.path.join(os.getcwd(), "scripts/javascript/"), animation_opts=opts.AnimationOpts(animation=False)) line1 = (Line(options).add_xaxis( hosts_metrics[host['ip']]['metrics']['datetime'] ).add_yaxis( "CPU", hosts_metrics[host['ip']]['metrics']['cpu'], is_symbol_show=False, is_smooth=True, areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode( "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'rgb(255,158,68)'},{offset:1,color:'rgb(255,70,131)'}])" ), opacity=0.5) ).add_yaxis( "Memory", hosts_metrics[host['ip']]['metrics']['memory'], is_symbol_show=False, is_smooth=True).set_series_opts(linestyle_opts=opts.LineStyleOpts( width=2)).set_global_opts( title_opts=opts.TitleOpts( title="主机资源使用率 (%s)" % (host['ip']), title_textstyle_opts=opts.TextStyleOpts(font_size=13), subtitle=" 数据来源-健康度平台"), xaxis_opts=opts.AxisOpts(type_="time"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts( formatter=utils.JsCode( "function(val){return val + '%';}"))))) line2 = (Line(options).add_xaxis( hosts_metrics[host['ip']]['metrics']['datetime'] ).add_yaxis( "Process", hosts_metrics[host['ip']]['metrics']['process'], is_symbol_show=False, is_smooth=True, areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode( "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#fff'},{offset:1,color:'#61a0a8'}])" ), opacity=0.5) ).set_series_opts(linestyle_opts=opts.LineStyleOpts( width=2)).set_global_opts( xaxis_opts=opts.AxisOpts( type_="time", position="top", axislabel_opts=opts.LabelOpts(is_show=False)), yaxis_opts=opts.AxisOpts(is_inverse=True), title_opts=opts.TitleOpts( title="应用运行数量(所有)", pos_bottom="0%", title_textstyle_opts=opts.TextStyleOpts(font_size=13)), legend_opts=opts.LegendOpts(pos_bottom="0%"))) grid = (Grid(options).add( line1, grid_opts=opts.GridOpts(pos_top=50, pos_left=50, pos_right=50, pos_bottom="50%")).add(line2, grid_opts=opts.GridOpts( pos_top="58%", pos_left=50, pos_right=50, pos_bottom=30))) make_snapshot( snapshot, grid.render( os.path.join(doc_path, "render_%s.html" % (host['ip'].replace(".", "_")))), os.path.join(doc_path, "host_res_%s.png" % (host['ip'].replace(".", "_"))), pixel_ratio=1, delay=1, is_remove_html=True)
def map_without_label(): obj_map = Map() obj_map.add("中国", [list(z) for z in zip(Faker.provinces, Faker.values())], "china") obj_map.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) obj_map.set_global_opts(title_opts=opts.TitleOpts(title="Map-不显示Label",subtitle ="副标题")) return obj_map
for i in range(2): for j in range(5): data_listy[i][j] = data[i][j][data_index[m]].astype(float).round( 2).tolist() n = n + 4 m = m + 1 except KeyError: pass # 将数据转换为pyecharts支持的数据类型 line = ( Line().add_xaxis(data_listx[0][0]) # 设置x轴数据 .add_yaxis( '1-1-C15', data_listy[0][0], # 设置y轴数据并调整样式 label_opts=opts.LabelOpts(is_show=False), # 不显示标签数据 linestyle_opts=opts.LineStyleOpts(), # 设置线的样式,暂不设置 itemstyle_opts=opts.ItemStyleOpts(opacity=0), # 将标签点的透明度设置为100% color='#000000', # 1-1-C15为纯黑 # 设置线条颜色 #is_smooth=True ).add_xaxis(data_listx[0][1]).add_yaxis( '1-2-C15', data_listy[0][1], label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(), itemstyle_opts=opts.ItemStyleOpts(opacity=0), color=' #808080', # 1-2-C15为灰色 #is_smooth=True ).add_xaxis(data_listx[0][2]).add_yaxis( '1-3-C15', data_listy[0][2],
def line_color_with_js_func(place="上海野生动物园") -> Line: if place is None: weather_data = weather_spider(weather_dict.get("上海野生动物园")) else: if place in weather_dict.keys(): place_weather_url = weather_dict.get(place) weather_data = weather_spider(place_weather_url) else: return None x_data = [ x.replace("".join(re.findall("(.*", x)), "") for x in weather_data.get("days") ] y_data = [ maxt.rstrip("℃").split("/")[0] for maxt in weather_data.get("max_min_t") ] y_data2 = [ mint.rstrip("℃").split("/")[1] for mint in weather_data.get("max_min_t") ] area_color_js = ( "new echarts.graphic.LinearGradient(0, 0, 0, 1, " "[{offset: 0, color: '#6495ED'}, {offset: 1, color: '#12406d'}], false)" ) c = ( Line(init_opts=opts.InitOpts( width="100%", height="100%")).set_series_opts( label_opts=opts.LabelOpts(is_show=True, color="white")). add_xaxis(xaxis_data=x_data).add_yaxis( "日最高气温", y_axis=y_data, is_smooth=True, is_symbol_show=True, symbol="circle", symbol_size=6, linestyle_opts=opts.LineStyleOpts(color="#fff"), label_opts=opts.LabelOpts(is_show=True, position="top", color="white", font_size=16), itemstyle_opts=opts.ItemStyleOpts(color="red", border_color="#fff", border_width=3), tooltip_opts=opts.TooltipOpts(is_show=False), areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1), ).set_global_opts( xaxis_opts=opts.AxisOpts( type_="category", boundary_gap=False, axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63"), axisline_opts=opts.AxisLineOpts(is_show=False), axistick_opts=opts.AxisTickOpts( is_show=True, length=25, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")), ), yaxis_opts=opts.AxisOpts( type_="value", position="right", axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")), axistick_opts=opts.AxisTickOpts( is_show=True, length=15, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")), ), legend_opts=opts.LegendOpts(is_show=False), ) # 第二 .add_xaxis(xaxis_data=x_data).add_yaxis( series_name="日最低气温", y_axis=y_data2, is_smooth=True, is_symbol_show=True, symbol="circle", symbol_size=6, linestyle_opts=opts.LineStyleOpts(color="#fff"), label_opts=opts.LabelOpts(is_show=True, position="top", color="white", font_size=16), itemstyle_opts=opts.ItemStyleOpts(color="#0ff", border_color="#fff", border_width=3), tooltip_opts=opts.TooltipOpts(is_show=False), areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1), ).set_global_opts( xaxis_opts=opts.AxisOpts( type_="category", boundary_gap=False, axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63"), axisline_opts=opts.AxisLineOpts(is_show=False), axistick_opts=opts.AxisTickOpts( is_show=True, length=25, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")), ), yaxis_opts=opts.AxisOpts( type_="value", position="right", axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")), axistick_opts=opts.AxisTickOpts( is_show=True, length=15, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")), ), legend_opts=opts.LegendOpts(is_show=False), )) return c
def geo(): place_avaliable = passenger_spider(None, all=True) place_no_weather = passenger_spider_no_weather() city = '上海' g = Geo(init_opts=opts.InitOpts( width="100%", height="100%", bg_color="#12406d")) g.add_schema(maptype=city, itemstyle_opts=opts.ItemStyleOpts(color="#135dbe", border_color="#fff"), zoom=1.2) # 定义坐标对应的名称,添加到坐标库中 add_coordinate(name, lng, lat) for k, v in jingwei_dict.items(): g.add_coordinate(k, float(v[1]), float(v[0])) for item in place_no_weather: g.add_coordinate(item["NAME"], float(item["LOCATION_X"]), float(item["LOCATION_Y"])) coordinates = [] for k in jingwei_dict.keys(): data_pairs = [] data_pairs.append(k) for p in place_avaliable: if k == p["NAME"]: if not p.get("MAX_NUM"): data_pairs.append(0.0) else: data_pairs.append( round(int(p["NUM"]) / int(p["MAX_NUM"]), 2)) break if len(data_pairs) == 1: data_pairs.append(0.0) data_pairs = tuple(data_pairs) coordinates.append(data_pairs) for item in place_no_weather: data_pairs = [] data_pairs.append(item["NAME"]) if (not item["MAX_NUM"]) or (item["MAX_NUM"] == ""): data_pairs.append(0) else: data_pairs.append(round( int(item["NUM"]) / int(item["MAX_NUM"]), 2)) data_pairs = tuple(data_pairs) coordinates.append(data_pairs) # 定义数据对, # data_pair = [ # ('湖南省长沙市雨花区跳马镇仙峰岭', 25), # ('湖南省长沙市宁乡市横市镇藕塘', 5), # ('湖南省长沙市长沙县黄花镇新塘铺长沙黄花国际机场', 20) # ] data_pair = coordinates # Geo 图类型,有 scatter, effectScatter, heatmap, lines 4 种,建议使用 # from pyecharts.globals import GeoType # GeoType.GeoType.EFFECT_SCATTER,GeoType.HEATMAP,GeoType.LINES # 将数据添加到地图上 g.add('', data_pair, type_=ChartType.EFFECT_SCATTER) # 设置样式 g.set_series_opts( label_opts=opts.LabelOpts(is_show=False, formatter="{b}:{c}")) # 自定义分段 color 可以用取色器取色 pieces = [ { 'max': 0.1, 'label': '10%以下', 'color': '#98F5FF' }, { 'min': 0.1, 'max': 0.3, 'label': '10%-30%', 'color': '#0f0' }, { 'min': 0.3, 'max': 0.5, 'label': '30%-50%', 'color': 'orange' }, { 'min': 0.5, 'max': 0.7, 'label': '50%-70%', 'color': '#E2C568' }, { 'min': 0.7, 'max': 0.8, 'label': '70%-80%', 'color': '#FCF84D' }, { 'min': 0.8, 'max': 0.9, 'label': '80%-90%', 'color': '#3700A4' }, { 'min': 0.9, 'max': 1, 'label': '90%-100%', 'color': '#DD675E' }, { 'min': 1, 'label': '100%以上', 'color': '#f00' } # 有下限无上限 ] # is_piecewise 是否自定义分段, 变为true 才能生效 g.set_global_opts( visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces, textstyle_opts=opts.TextStyleOpts( color="#fff"))) return g
def global_total_map(wb): ws_time = wb['全球疫情数据更新时间'] ws_data = wb['全球各国疫情数据'] ws_data.delete_rows(1) country = [] surplus = [] curconfirm = [] for data in ws_data.values: country.append(data[0]) surplus.append(data[1]) curconfirm.append(data[2]) time_global = ws_time['A2'].value pieces = [{ 'max': 0, 'min': 0, 'label': '0', 'color': '#FFFFFF' }, { 'max': 49, 'min': 1, 'label': '1-49', 'color': '#FFE5DB' }, { 'max': 99, 'min': 50, 'label': '50-99', 'color': '#FFC4B3' }, { 'max': 999, 'min': 100, 'label': '100-999', 'color': '#FF9985' }, { 'max': 9999, 'min': 1000, 'label': '1000-9999', 'color': '#F57567' }, { 'max': 99999, 'min': 10000, 'label': '10000-99999', 'color': '#E64546' }, { 'max': 999999, 'min': 100000, 'label': '100000-999999', 'color': '#B80909' }, { 'max': 9999999, 'min': 1000000, 'label': '1000000-9999999', 'color': '#BA0808' }, { 'max': 99999999, 'min': 10000000, 'label': '>=10000000', 'color': '#F00000' }] name_map = { "Somalia": "索马里", "Liechtenstein": "列支敦士登", "Morocco": "摩洛哥", "W. Sahara": "西撒哈拉", "Serbia": "塞尔维亚", "Afghanistan": "阿富汗", "Angola": "安哥拉", "Albania": "阿尔巴尼亚", "Andorra": "安道尔共和国", "United Arab Emirates": "阿拉伯联合酋长国", "Argentina": "阿根廷", "Armenia": "亚美尼亚", "Australia": "澳大利亚", "Austria": "奥地利", "Azerbaijan": "阿塞拜疆", "Burundi": "布隆迪", "Belgium": "比利时", "Benin": "贝宁", "Burkina Faso": "布基纳法索", "Bangladesh": "孟加拉国", "Bulgaria": "保加利亚", "Bahrain": "巴林", "Bahamas": "巴哈马", "Bosnia and Herz.": "波斯尼亚和黑塞哥维那", "Belarus": "白俄罗斯", "Belize": "伯利兹", "Bermuda": "百慕大", "Bolivia": "玻利维亚", "Brazil": "巴西", "Barbados": "巴巴多斯", "Brunei": "文莱", "Bhutan": "不丹", "Botswana": "博茨瓦纳", "Central African Rep.": "中非共和国", "Canada": "加拿大", "Switzerland": "瑞士", "Chile": "智利", "China": "中国", "Côte d'Ivoire": "科特迪瓦", "Cameroon": "喀麦隆", "Dem. Rep. Congo": "刚果(布)", "Congo": "刚果(金)", "Colombia": "哥伦比亚", "Cape Verde": "佛得角", "Costa Rica": "哥斯达黎加", "Cuba": "古巴", "N. Cyprus": "北塞浦路斯", "Cyprus": "塞浦路斯", "Czech Rep.": "捷克", "Germany": "德国", "Djibouti": "吉布提", "Denmark": "丹麦", "Dominican Rep.": "多米尼加", "Algeria": "阿尔及利亚", "Ecuador": "厄瓜多尔", "Egypt": "埃及", "Eritrea": "厄立特里亚", "Spain": "西班牙", "Estonia": "爱沙尼亚", "Ethiopia": "埃塞俄比亚", "Finland": "芬兰", "Fiji": "斐济", "France": "法国", "Gabon": "加蓬", "United Kingdom": "英国", "Georgia": "格鲁吉亚", "Ghana": "加纳", "Guinea": "几内亚", "Gambia": "冈比亚", "Guinea-Bissau": "几内亚比绍", "Eq. Guinea": "赤道几内亚", "Greece": "希腊", "Grenada": "格林纳达", "Greenland": "格陵兰岛", "Guatemala": "危地马拉", "Guam": "关岛", "Guyana": "圭亚那合作共和国", "Honduras": "洪都拉斯", "Croatia": "克罗地亚", "Haiti": "海地", "Hungary": "匈牙利", "Indonesia": "印度尼西亚", "India": "印度", "Br. Indian Ocean Ter.": "英属印度洋领土", "Ireland": "爱尔兰", "Iran": "伊朗", "Iraq": "伊拉克", "Iceland": "冰岛", "Israel": "以色列", "Italy": "意大利", "Jamaica": "牙买加", "Jordan": "约旦", "Japan": "日本", "Siachen Glacier": "锡亚琴冰川", "Kazakhstan": "哈萨克斯坦", "Kenya": "肯尼亚", "Kyrgyzstan": "吉尔吉斯斯坦", "Cambodia": "柬埔寨", "Korea": "韩国", "Kuwait": "科威特", "Lao PDR": "老挝", "Lebanon": "黎巴嫩", "Liberia": "利比里亚", "Libya": "利比亚", "Sri Lanka": "斯里兰卡", "Lesotho": "莱索托", "Lithuania": "立陶宛", "Luxembourg": "卢森堡", "Latvia": "拉脱维亚", "Moldova": "摩尔多瓦", "Madagascar": "马达加斯加", "Mexico": "墨西哥", "Macedonia": "马其顿", "Mali": "马里", "Malta": "马耳他", "Myanmar": "缅甸", "Montenegro": "黑山", "Mongolia": "蒙古国", "Mozambique": "莫桑比克", "Mauritania": "毛里塔尼亚", "Mauritius": "毛里求斯", "Malawi": "马拉维", "Malaysia": "马来西亚", "Namibia": "纳米比亚", "New Caledonia": "新喀里多尼亚", "Niger": "尼日尔", "Nigeria": "尼日利亚", "Nicaragua": "尼加拉瓜", "Netherlands": "荷兰", "Norway": "挪威", "Nepal": "尼泊尔", "New Zealand": "新西兰", "Oman": "阿曼", "Pakistan": "巴基斯坦", "Panama": "巴拿马", "Peru": "秘鲁", "Philippines": "菲律宾", "Papua New Guinea": "巴布亚新几内亚", "Poland": "波兰", "Puerto Rico": "波多黎各", "Dem. Rep. Korea": "朝鲜", "Portugal": "葡萄牙", "Paraguay": "巴拉圭", "Palestine": "巴勒斯坦", "Qatar": "卡塔尔", "Romania": "罗马尼亚", "Russia": "俄罗斯", "Rwanda": "卢旺达", "Saudi Arabia": "沙特阿拉伯", "Sudan": "苏丹", "S. Sudan": "南苏丹", "Senegal": "塞内加尔", "Singapore": "新加坡", "Solomon Is.": "所罗门群岛", "Sierra Leone": "塞拉利昂", "El Salvador": "萨尔瓦多", "Suriname": "苏里南", "Slovakia": "斯洛伐克", "Slovenia": "斯洛文尼亚", "Sweden": "瑞典", "Swaziland": "斯威士兰", "Seychelles": "塞舌尔", "Syria": "叙利亚", "Chad": "乍得", "Togo": "多哥", "Thailand": "泰国", "Tajikistan": "塔吉克斯坦", "Turkmenistan": "土库曼斯坦", "Timor-Leste": "东帝汶", "Tonga": "汤加", "Trinidad and Tobago": "特立尼达和多巴哥", "Tunisia": "突尼斯", "Turkey": "土耳其", "Tanzania": "坦桑尼亚", "Uganda": "乌干达", "Ukraine": "乌克兰", "Uruguay": "乌拉圭", "United States": "美国", "Uzbekistan": "乌兹别克斯坦", "Venezuela": "委内瑞拉", "Vietnam": "越南", "Vanuatu": "瓦努阿图", "Yemen": "也门", "South Africa": "南非", "Zambia": "赞比亚", "Zimbabwe": "津巴布韦", "Aland": "奥兰群岛", "American Samoa": "美属萨摩亚", "Fr. S. Antarctic Lands": "南极洲", "Antigua and Barb.": "安提瓜和巴布达", "Comoros": "科摩罗", "Curaçao": "库拉索岛", "Cayman Is.": "开曼群岛", "Dominica": "多米尼加", "Falkland Is.": "福克兰群岛马尔维纳斯", "Faeroe Is.": "法罗群岛", "Micronesia": "密克罗尼西亚", "Heard I. and McDonald Is.": "赫德岛和麦克唐纳群岛", "Isle of Man": "曼岛", "Jersey": "泽西岛", "Kiribati": "基里巴斯", "Saint Lucia": "圣卢西亚", "N. Mariana Is.": "北马里亚纳群岛", "Montserrat": "蒙特塞拉特", "Niue": "纽埃", "Palau": "帕劳", "Fr. Polynesia": "法属波利尼西亚", "S. Geo. and S. Sandw. Is.": "南乔治亚岛和南桑威奇群岛", "Saint Helena": "圣赫勒拿", "St. Pierre and Miquelon": "圣皮埃尔和密克隆群岛", "São Tomé and Principe": "圣多美和普林西比", "Turks and Caicos Is.": "特克斯和凯科斯群岛", "St. Vin. and Gren.": "圣文森特和格林纳丁斯", "U.S. Virgin Is.": "美属维尔京群岛", "Samoa": "萨摩亚" } gt_map = (Map().add( series_name='累计确诊人数', data_pair=[list(z) for z in zip(country, curconfirm)], maptype="world", name_map=name_map, is_map_symbol_show=False).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="全球疫情数据(累计确诊)", subtitle='数据更新至:' + time_global + '\n\n来源:百度疫情实时大数据报告'), visualmap_opts=opts.VisualMapOpts( max_=300, is_piecewise=True, pieces=pieces)).dump_options_with_quotes()) gs_map = (Map().add( series_name='现有确诊人数', data_pair=[list(z) for z in zip(country, surplus)], maptype="world", name_map=name_map, is_map_symbol_show=False).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="全球疫情数据(现有确诊)", subtitle='数据更新至:' + time_global + '\n\n来源:百度疫情实时大数据报告'), visualmap_opts=opts.VisualMapOpts( max_=300, is_piecewise=True, pieces=pieces)).dump_options_with_quotes()) return gt_map, gs_map
) # 3、全局配置 pie.set_global_opts( # 标题配置项 title_opts=opts.TitleOpts( title='Python分校人数占比饼图', # 饼图标题 subtitle='广州Python0624班级全体', # 子标题 pos_left='left', # 标题距离左侧的间距,居左显示 ), # 图例配置项 legend_opts=opts.LegendOpts( type_='plain', # 图例类型 --普通图例 # type_='scroll', # 图例类型 --滚动图例 is_show=True, # 显示图例 pos_left='center', # 图例居中 pos_top='top')) # 4、系列配置 pie.set_series_opts( # 标签设置 label_opts=opts.LabelOpts( is_show=True, # 显示标签 font_size=12, # 标签字体大小 font_style='italic', # 字体倾斜 formatter='{b}:{d}%', # 显示格式 )) # 5、生成图像 pie.render('./html/饼图绘制.html')
'South Africa': '南非', 'Zambia': '赞比亚', 'Zimbabwe': '津巴布韦', 'China': '中国' } map_ = Map(opts.InitOpts(width='1200px', height='600px')).add( series_name="地区累计确诊", # 设置提示框标签 data_pair=a, # 输入数据 maptype="world", # 设置地图类型为世界地图 name_map=nameMap, # 添加映射 is_map_symbol_show=False # 不显示标记点 ) # 设置系列配置项 map_.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) # 不显示国家名称 # 设置全局配置项 map_.set_global_opts( title_opts=opts.TitleOpts(title=""), # 设置图标题 visualmap_opts=opts.VisualMapOpts(max_=1000000, is_piecewise=True)) # 显示图例 # map_.set_global_opts(title_opts=opts.TitleOpts(title="国外疫情情况"), # 设置图标题 # visualmap_opts=opts.VisualMapOpts(pieces=[ # 自定义分组的分店和颜色 # {"min": 900000, "color": "#800000"}, # {"min": 50000, "max": 500000, "lable":'0.15~0.19', "color": "#AA0000"}, # 栗色 # {"min": 10000, "max": 50000, "color": "#CC0000"}, # 耐火砖 # {"min": 1000, "max": 10000, "color": "#FF0000"}, # 印度红 # {"min": 0, "max": 1000, "color": "#FF3333"}, # 玫瑰棕色 # {"max": 0, "color": "#FFCCCC"}, # 薄雾玫瑰 # ],
links = [] for i in groups.values: dic = {} dic['source'] = i[0] dic['target'] = i[1] dic['value'] = i[2] links.append(dic) pic = Sankey().add( '', #图例名 nodes, #节点数据 links, #边和流量数据 #透明度、弯曲度、颜色 linestyle_opt=opts.LineStyleOpts(opacity=0.3, curve=0.5, color='source'), #标签显示位置 label_opts=opts.LabelOpts(position='right'), #节点之间距离 node_gap=30, ).set_global_opts(title_opts=opts.TitleOpts(title='幸福感指数相关性桑基图')) pic.render('test.html') df['survey_time'] = df['survey_time'].apply(lambda x: int(x[:4])) def split_age(x): if x < 20: return 1 elif x < 40: return 2 elif x < 60:
1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色 """ v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] (Radar(init_opts=opts.InitOpts(bg_color="#CCCCCC")).add_schema( schema=[ opts.RadarIndicatorItem(name="销售(sales)", max_=6500), opts.RadarIndicatorItem(name="管理(Administration)", max_=16000), opts.RadarIndicatorItem(name="信息技术(Information Technology)", max_=30000), opts.RadarIndicatorItem(name="客服(Customer Support)", max_=38000), opts.RadarIndicatorItem(name="研发(Development)", max_=52000), opts.RadarIndicatorItem(name="市场(Marketing)", max_=25000), ], splitarea_opt=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), textstyle_opts=opts.TextStyleOpts(color="#fff"), ).add( series_name="预算分配(Allocated Budget)", data=v1, linestyle_opts=opts.LineStyleOpts(color="#CD0000"), ).add( series_name="实际开销(Actual Spending)", data=v2, linestyle_opts=opts.LineStyleOpts(color="#5CACEE"), ).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="基础雷达图"), legend_opts=opts.LegendOpts()).render("basic_radar_chart.html"))
Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.baidu.com/examples/editor.html?c=line-smooth 目前无法实现的功能: 暂无 """ x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] y_data = [820, 932, 901, 934, 1290, 1330, 1320] c = (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, is_smooth=True, label_opts=opts.LabelOpts(is_show=False), )) c.width = "100%" put_html(c.render_notebook())
from pywebio.output import put_html from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c = (Pie().add( "", [list(z) for z in zip(Faker.choose(), Faker.values())]).set_global_opts( title_opts=opts.TitleOpts(title="Pie-基本示例")).set_series_opts( label_opts=opts.LabelOpts(formatter="{b}: {c}"))) c.width = "100%" put_html(c.render_notebook())
p = ( Pie(init_opts=opts.InitOpts(bg_color='#031f2d', )).set_global_opts( title_opts=opts.TitleOpts(title="%d年\n\n不同空军机型统计" % (years[i], ), pos_left='center', pos_top='40%', padding=[24, 0], title_textstyle_opts=opts.TextStyleOpts( color='#fff', font_size=18, align='center')), legend_opts=opts.LegendOpts( type_="scroll", pos_left="80%", orient="vertical", textstyle_opts=opts.TextStyleOpts(color='#fff', font_size=16, rich=rich), )). add( "xilie1", datalist[i], radius=['42%', '50%'], label_opts=opts.LabelOpts( position="outside", rich=rich, formatter= "{white|{b}} \n{hr|}\n{yellow|{c}}\n{blue|{d}%}" # 参数说明:{a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比) ))) tl.add(p, "{}年".format(years[i])) tl.render("timeline_pie.html")
# ["Perth", 5386, 1554769, 869.4], # ] table.add(headers, rows) table.set_global_opts( title_opts=ComponentTitleOpts( title="Statistics of the Lexicon", subtitle="The data source and respective statistics including the \ number of word with one/two/three/four/more-than-four Chinese characters etc.") ) # table.render_notebook() table.render("lexicon_stat.html") # %% bar = Bar(init_opts=opts.InitOpts( chart_id="id", width="600PX", theme=ThemeType.LIGHT, bg_color="white")) bar.add_xaxis([key for key, _ in data_source_word_cnt.items()]) bar.add_yaxis(None, [value for key, value in data_source_word_cnt.items()]) bar.set_global_opts(title_opts=opts.TitleOpts(title="#words of each dictionary", subtitle=None)) bar.reversal_axis() bar.set_series_opts(label_opts=opts.LabelOpts(position="right")) bar.render_notebook() # %%
[1, 5, 41], [2, 5, 110], [3, 5, 39], [4, 5, 40], [5, 5, 90], [6, 5, 50], [7, 5, 60], [8, 5, 146], [9, 5, 15], ] axisOpts = opts.AxisOpts( type_="category", axisline_opts=opts.AxisLineOpts(is_show=False), axislabel_opts=opts.LabelOpts( color='#A3C7E7', font_size=10, ), axistick_opts=opts.AxisTickOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts( is_show=True, color='black', width=10, )), ) c = ( HeatMap(init_opts=opts.InitOpts(bg_color='black', )).add_xaxis( xdata).add_yaxis( "月份", ydata,
def full_chart(mydate, kdata, data_5, data_10, data_20, volume_rise, volume_drop, name): kline = ( Kline() .add_xaxis(mydate) .add_yaxis("%s" % name, kdata, markpoint_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(type_="max", value_dim="close")] ), markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(type_="max", value_dim="close")] ), itemstyle_opts=opts.ItemStyleOpts( color="#ec0000", color0="#00da3c", border_color="#8A0000", border_color0="#008F28", ), ) .set_global_opts( yaxis_opts=opts.AxisOpts(is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), xaxis_opts=opts.AxisOpts(is_scale=True, axislabel_opts=opts.LabelOpts(rotate=-30)), title_opts=opts.TitleOpts(title="股票走势"), datazoom_opts=[opts.DataZoomOpts(xaxis_index=[0, 1])], toolbox_opts=opts.ToolboxOpts(is_show=True), legend_opts=opts.LegendOpts(pos_left="20%") ) ) line = ( Line() .add_xaxis(mydate) .add_yaxis("Ma5", data_5, is_smooth=True) .add_yaxis("Ma10", data_10, is_smooth=True) .add_yaxis("Ma20", data_20, is_smooth=True) .set_global_opts(title_opts=opts.TitleOpts(title="移动平均线")) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), ) ) bar = ( Bar() .add_xaxis(mydate) .add_yaxis("volume_rise", volume_rise, stack=True, color=["#ec0000"], ) .add_yaxis("volume_drop", volume_drop, stack=True, color=["#00da3c"], ) .set_global_opts(title_opts=opts.TitleOpts(), legend_opts=opts.LegendOpts(pos_right="20%")) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), ) ) overlap_kline_line = kline.overlap(line) grid = Grid() grid.add( overlap_kline_line, grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="50%"), ) grid.add( bar, grid_opts=opts.GridOpts( pos_left="10%", pos_right="8%", pos_top="70%", height="16%" ), ) return grid
lista1[i] = line[0] line = f1.readline() i = i + 1 f1.close() ( #颜色 Pie(init_opts=opts.InitOpts(bg_color="#2c343c")).add( #名称 series_name="第四阶段", data_pair=[list(z) for z in zip(lista1, x1)], radius=["40%", "65%"], #圆心位置 center=["50%", "50%"], #标签 label_opts=opts.LabelOpts(is_show=False, position="center"), ).set_global_opts( #标题 title_opts=opts.TitleOpts( #名字 title="江苏第四阶段心态空心图", pos_left="center", pos_top="20", #标题颜色 title_textstyle_opts=opts.TextStyleOpts(color="#fff"), ), #没用 legend_opts=opts.LegendOpts(is_show=False), ) #系列 .set_series_opts(
.add(map_chart, grid_opts=opts.GridOpts()) ) return grid_chart if __name__ == '__main__': timeline = Timeline( init_opts=opts.InitOpts( width="1600px", height="900px", theme=ThemeType.DARK) ) for y in time_list: g = get_year_chart(year=y) timeline.add(g, time_point=str(y)) timeline.add_schema( orient="vertical", is_auto_play=True, is_inverse=True, play_interval=1200, pos_left="null", pos_right="5", pos_top="20", pos_bottom="20", width="60", label_opts=opts.LabelOpts(is_show=True, color="#fff"), ) timeline.render("NCP.html") print(MapData)
line.add_xaxis(dateId) line.add_yaxis( "全国新增确诊病例", #图例 all_statis, #数据 is_smooth=True, #是否平滑曲线 linestyle_opts=opts.LineStyleOpts(width=4, color='#B44038'), #线样式配置项 itemstyle_opts=opts.ItemStyleOpts( color='#B44038', #图元样式配置项 border_color="#B44038", #颜色 border_width=10)) #图元的大小 line.add_yaxis( "湖北新增确诊病例", hubei_statis, is_smooth=True, linestyle_opts=opts.LineStyleOpts(width=2, color='#4E87ED'), label_opts=opts.LabelOpts(position='bottom'), #标签在折线的底部 itemstyle_opts=opts.ItemStyleOpts(color='#4E87ED', border_color="#4E87ED", border_width=3)) line.add_yaxis( "其他省份新增病例", other_statis, is_smooth=True, linestyle_opts=opts.LineStyleOpts(width=2, color='#F1A846'), label_opts=opts.LabelOpts(position='bottom'), #标签在折线的底部 itemstyle_opts=opts.ItemStyleOpts(color='#F1A846', border_color="#F1A846", border_width=3)) line.set_global_opts( title_opts=opts.TitleOpts(title="新增确诊病例", subtitle='数据来源:丁香园'), yaxis_opts=opts.AxisOpts(
def get_year_chart(year: str): map_data = [ [[x["name"], x["value"]] for x in d["data"]] for d in MapData if d["time"] == year ][0] min_data, max_data = (minNum, maxNum) data_mark: List = [] i = 0 for x in time_list: if x == year: data_mark.append(total_num[i]) else: data_mark.append("") i = i + 1 map_chart = ( Map() .add( series_name="", data_pair=map_data, zoom=1, center=[119.5, 34.5], is_map_symbol_show=False, itemstyle_opts={ "normal": {"areaColor": "#323c48", "borderColor": "#404a59"}, "emphasis": { "label": {"show": Timeline}, "areaColor": "rgba(255,255,255, 0.5)", }, }, ) .set_global_opts( title_opts=opts.TitleOpts( title="" + str(year) + "全国各省份NCP实时动态(数据来源:丁香园; 数据仓库:BlankerL/DXY-2019-nCoV-Data)", subtitle="", pos_left="center", pos_top="top", title_textstyle_opts=opts.TextStyleOpts( font_size=25, color="rgba(255,255,255, 0.9)" ), ), tooltip_opts=opts.TooltipOpts( is_show=True, formatter=JsCode( """function(params) { if ('value' in params.data) { return params.data.value[2] + ': ' + params.data.value[0]; } }""" ), ), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="30", pos_top="center", range_text=["High", "Low"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=min_data, max_=max_data, ), ) ) line_chart = ( Line() .add_xaxis(time_list) .add_yaxis("", total_num) .add_yaxis( "", data_mark, markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max")]), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts( title="全国各省份NCP实时动态(单位: 百人)", pos_left="72%", pos_top="5%" ) ) ) bar_x_data = [x[0] for x in map_data] bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data] bar = ( Bar() .add_xaxis(xaxis_data=bar_x_data) .add_yaxis( series_name="", yaxis_data=bar_y_data, label_opts=opts.LabelOpts( is_show=True, position="right", formatter="{b} : {c}" ), ) .reversal_axis() .set_global_opts( xaxis_opts=opts.AxisOpts( max_=maxCount, axislabel_opts=opts.LabelOpts(is_show=False) ), yaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(is_show=False)), tooltip_opts=opts.TooltipOpts(is_show=False), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="10", pos_top="top", range_text=["High", "Low"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=min_data, max_=max_data, ), ) ) pie_data = [[x[0], x[1][0]] for x in map_data] pie = ( Pie() .add( series_name="", data_pair=pie_data, radius=["15%", "35%"], center=["80%", "82%"], itemstyle_opts=opts.ItemStyleOpts( border_width=1, border_color="rgba(0,0,0,0.5)" ), ) .set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"), legend_opts=opts.LegendOpts(is_show=False), ) ) grid_chart = ( Grid() .add( bar, grid_opts=opts.GridOpts( pos_left="10", pos_right="45%", pos_top="50%", pos_bottom="5" ), ) .add( line_chart, grid_opts=opts.GridOpts( pos_left="65%", pos_right="80", pos_top="10%", pos_bottom="50%" ), ) .add(pie, grid_opts=opts.GridOpts(pos_left="45%", pos_top="60%")) .add(map_chart, grid_opts=opts.GridOpts()) ) return grid_chart
data_lr_fb_p = pd.pivot_table(data_lr_fb, values='IND_VAL', index='ORG_NUM', columns='INDIC_KEY', aggfunc=np.sum, fill_value=0) data_lr_fb_p.drop(['BSBK9999'], inplace=True) data_lr_fb_p = data_lr_fb_p.reset_index() # print(data_lr_fb_p) c = (Pie(init_opts=opts.InitOpts( width='1500px', height='760px', )).add( "", [ list(z) for z in zip(data_lr_fb_p['ORG_NUM'], data_lr_fb_p['ZCFZ_A_113']) ], radius=["1%", "60%"], center=["35%", "50%"]).add( "", [ list(z) for z in zip(data_lr_fb_p['ORG_NUM'], data_lr_fb_p['ZCFZ_B_208']) ], radius=["1%", "60%"], center=["75%", "50%"]).set_global_opts( title_opts=opts.TitleOpts(title="贷款、存款分布情况", subtitle="(单位:亿元)"), legend_opts=opts.LegendOpts( orient="vertical", pos_top="15%", pos_left="2%")).set_series_opts(label_opts=opts.LabelOpts( formatter="{d}%")).render("pie_base.html"))
def dray_line_piture(self,my_line_data_x,my_line_data_y): if os.path.isfile('.\line_color.html'): os.remove('.\line_color.html') if(len(my_line_data_x) != len(my_line_data_y)): print("leng not match !!!") exit() x_data = my_line_data_x y_data = my_line_data_y #print(x_data) #print(y_data) background_color_js = ( "new echarts.graphic.LinearGradient(0, 0, 0, 1, " "[{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)" ) area_color_js = ( "new echarts.graphic.LinearGradient(0, 0, 0, 1, " "[{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)" ) c = ( Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js))) .add_xaxis(xaxis_data=x_data) .add_yaxis( series_name="注册总量", y_axis=y_data, is_smooth=True, is_symbol_show=True, symbol="circle", symbol_size=6, linestyle_opts=opts.LineStyleOpts(color="#fff"), label_opts=opts.LabelOpts(is_show=True, position="top", color="white",formatter="{c}%"), itemstyle_opts=opts.ItemStyleOpts( color="red", border_color="#fff", border_width=3 ), tooltip_opts=opts.TooltipOpts(is_show=False), areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1), ) .set_global_opts( title_opts=opts.TitleOpts( title="Yield", pos_left="5%", pos_top="5%", title_textstyle_opts=opts.TextStyleOpts(color="#fff", font_size=16), ), xaxis_opts=opts.AxisOpts( type_="category", boundary_gap=False, axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63"), axisline_opts=opts.AxisLineOpts( #is_show=False, linestyle_opts=opts.LineStyleOpts(width=2, color="#fff") ), axistick_opts=opts.AxisTickOpts( is_show=True, length=25, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f") ), ), yaxis_opts=opts.AxisOpts( type_="value", position="right", axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(width=2, color="#fff") ), axistick_opts=opts.AxisTickOpts( is_show=False, length=15, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"), ), splitline_opts=opts.SplitLineOpts( is_show=False, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f") ), ), legend_opts=opts.LegendOpts(is_show=False), ) .render("line_color.html") )
yaxis_index=0, color="#d14a61", ).add_yaxis( "降水量", [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3], yaxis_index=1, color="#5793f3", ).extend_axis(yaxis=opts.AxisOpts( name="蒸发量", type_="value", min_=0, max_=250, position="right", axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts( color="#d14a61")), axislabel_opts=opts.LabelOpts(formatter="{value} ml"), )).extend_axis(yaxis=opts.AxisOpts( type_="value", name="温度", min_=0, max_=25, position="left", axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts( color="#675bba")), axislabel_opts=opts.LabelOpts(formatter="{value} °C"), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(opacity=1)), )).set_global_opts( yaxis_opts=opts.AxisOpts( name="降水量", min_=0,
def draw_rose_piture(self,my_rose_data): total_position = 0 for x in my_rose_data: total_position = total_position + x[1] #print(total_position) if os.path.isfile('pie_rosetype.html'): os.remove('.\pie_rosetype.html') c = ( Pie() .add( "", my_rose_data, radius=["30%", "75%"], #center=["25%", "50%"], rosetype="radius", #label_opts=opts.LabelOpts(is_show=False), ) #.add( # "", # my_rose_data, # radius=["30%", "75%"], # center=["75%", "50%"], # rosetype="area", #) .set_global_opts( title_opts=opts.TitleOpts(title="Positions",pos_left="8%",pos_top="8%"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 right="15%", bottom="5%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 #opts.GraphicRect( # graphic_item=opts.GraphicItem( # z=100, # right="center", # bottom="middle", # ), # graphic_shape_opts=opts.GraphicShapeOpts( # width=120, height=70, # ), # graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( # fill="#fff", # stroke="#555", # line_width=2, # shadow_blur=8, # shadow_offset_x=3, # shadow_offset_y=3, # shadow_color="rgba(144,238,144,0.3)", # ) #), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text="Total:"+str(total_position)+"%", font="bolder 21px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#C537B6" ) ) ) ] ) ] ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b} {c}%")) .render("pie_rosetype.html") )
def generate_bar_html(rows, title): x = [] y = [] for row in rows: x.append(row[0]) y.append({'value': row[1], 'range': [row[2], row[3]]}) bar = Bar(init_opts=opts.InitOpts(height='700px', width='1424px', theme=ThemeType.SHINE, chart_id="cb_tree_map")) bar.add_xaxis(x) bar.add_yaxis( "个数", y, yaxis_index=0, bar_width=50, category_gap='1%', gap='1%', label_opts=opts.LabelOpts( position="top", formatter=JsCode("function(x){return x.data[0];}")), ) bar.set_series_opts(itemstyle_opts=opts.ItemStyleOpts(color=JsCode( "function(x){return x.data['range'][0]=='0'?'lightgray':(x.data['range'][0] < 0 ? 'lightgreen':'lightcoral')}" ))) bar.set_global_opts( title_opts=opts.TitleOpts( title="=========" + title + "=========", subtitle_textstyle_opts=opts.TextStyleOpts(font_weight='bold', font_size='15px'), pos_left='center', pos_top='-1px', ), tooltip_opts=opts.TooltipOpts(is_show=False), legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts( # data=None, # type_='category', # name_gap=0, # name_rotate=90, # axislabel_opts=opts.LabelOpts( # rotate=-60, # ), name='价格涨跌区间', name_gap=35, is_scale=True, name_location='middle', splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_on_zero=True, # symbol=['none', 'arrow'] )), yaxis_opts=opts.AxisOpts( type_='value', name='个数', # name_rotate=90, name_gap=35, name_location='middle', # min_=0, # max_=max_value, is_scale=True, axislabel_opts=opts.LabelOpts(formatter='{value}'), splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_on_zero=False, # symbol=['none', 'arrow'] )), ) bar_html = bar.render_embed('template.html', html_utils.env) return bar_html
def radar_air_quality() -> Radar: value_bj = [ [55, 9, 56, 0.46, 18, 6, 1], [25, 11, 21, 0.65, 34, 9, 2], [56, 7, 63, 0.3, 14, 5, 3], [33, 7, 29, 0.33, 16, 6, 4], [42, 24, 44, 0.76, 40, 16, 5], [82, 58, 90, 1.77, 68, 33, 6], [74, 49, 77, 1.46, 48, 27, 7], [78, 55, 80, 1.29, 59, 29, 8], [267, 216, 280, 4.8, 108, 64, 9], [185, 127, 216, 2.52, 61, 27, 10], [39, 19, 38, 0.57, 31, 15, 11], [41, 11, 40, 0.43, 21, 7, 12], ] value_sh = [ [91, 45, 125, 0.82, 34, 23, 1], [65, 27, 78, 0.86, 45, 29, 2], [83, 60, 84, 1.09, 73, 27, 3], [109, 81, 121, 1.28, 68, 51, 4], [106, 77, 114, 1.07, 55, 51, 5], [109, 81, 121, 1.28, 68, 51, 6], [106, 77, 114, 1.07, 55, 51, 7], [89, 65, 78, 0.86, 51, 26, 8], [53, 33, 47, 0.64, 50, 17, 9], [80, 55, 80, 1.01, 75, 24, 10], [117, 81, 124, 1.03, 45, 24, 11], [99, 71, 142, 1.1, 62, 42, 12], ] c_schema = [ { "name": "AQI", "max": 300, "min": 5 }, { "name": "PM2.5", "max": 250, "min": 20 }, { "name": "PM10", "max": 300, "min": 5 }, { "name": "CO", "max": 5 }, { "name": "NO2", "max": 200 }, { "name": "SO2", "max": 100 }, ] c = (Radar().add_schema(schema=c_schema, shape="circle").add( "北京", value_bj, color="#f9713c").add("上海", value_sh, color="#b3e4a1").set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="Radar-空气质量"))) return c