def geo_echart_countries_js() -> Geo: register_url("https://echarts-maps.github.io/echarts-countries-js/") geo = ( Geo() .add_schema(maptype="瑞士") .set_global_opts(title_opts=opts.TitleOpts(title="瑞士")) ) return geo
def test_register_url(fake): current_path = os.path.dirname(__file__) with open( os.path.join(current_path, "fixtures", "registry.json"), encoding="utf8" ) as f: fake.return_value = f register_url("fake_url") eq_( EXTRA, { "https://echarts-maps.github.io/echarts-china-cities-js/js/": { "安庆": ["shape-with-internal-borders/an1_hui1_an1_qing4", "js"] } }, )
def test_register_url(fake): current_path = os.path.dirname(__file__) fake_registry = os.path.join(current_path, "fixtures", "registry.json") file_name = ["shape-with-internal-borders/an1_hui1_an1_qing4", "js"] with open(fake_registry, encoding="utf8") as f: fake.return_value = f register_url("http://register.url/is/used") assert_equal( EXTRA, { "http://register.url/is/used/js/": { "安庆": file_name, "English Name": file_name, } }, )
def get_map_base(self, _data): ''' plot geo-VisualMap :param _data: gps对应的城市分布(dataframe) :return: 热点图 ''' register_url(self.echarts_url) c_map = Map(init_opts=opts.InitOpts( width="1000px", height="600px", page_title='', bg_color='')) c_map.add(series_name=self.series_name, data_pair=_data, maptype=self.country) c_map.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) c_map.set_global_opts( title_opts=opts.TitleOpts(title="Map-VisualMap"), visualmap_opts=opts.VisualMapOpts(max_=self.threshold_plot)) return c_map
def geo_base() -> Map: register_url("https://echarts-maps.github.io/echarts-countries-js/") c = ( Map() .add("South Atlantic",(list(z) for z in zip(MapSA,dataSA)),maptype = "美国", is_map_symbol_show = False) .add("Pacific", (list(z) for z in zip(MapPaci, dataPaci)), maptype="美国", is_map_symbol_show=False) .add("East North Central", (list(z) for z in zip(MapENC, dataENC)), maptype="美国", is_map_symbol_show=False) .add("East South Central", (list(z) for z in zip(MapESC, dataESC)), maptype="美国", is_map_symbol_show=False) .add("West South Central", (list(z) for z in zip(MapWSC, dataWSC)), maptype="美国", is_map_symbol_show=False) .add("West North Central", (list(z) for z in zip(MapWNC, dataWNC)), maptype="美国", is_map_symbol_show=False) .add("New England", (list(z) for z in zip(MapNE, dataNE)), maptype="美国", is_map_symbol_show=False) .add("Mountain", (list(z) for z in zip(MapMou, dataMou)), maptype="美国", is_map_symbol_show=False) .add("Middle Atlantic", (list(z) for z in zip(MapMA, dataMA)), maptype="美国", is_map_symbol_show=False) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( visualmap_opts=opts.VisualMapOpts(), # title_opts=opts.TitleOpts(title="Geo-基本示例"), ) ) return c
def get_geo_base(self, _data): ''' plot geo-HeatMap :param _data: gps对应的城市分布(dataframe) :return: geo城市分布图 ''' register_url(self.echarts_url) geo = Geo(init_opts=opts.InitOpts(width="1000px", height="600px", page_title=self.country, bg_color='')) geo.add_schema(maptype=self.country) for _city, _gps in self.geo_dict.items(): geo.add_coordinate(name=_city, longitude=_gps[0], latitude=_gps[1]) geo.add(series_name=self.series_name, data_pair=_data, type_=ChartType.HEATMAP) geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) geo.set_global_opts( visualmap_opts=opts.VisualMapOpts(max_=self.threshold_plot), title_opts=opts.TitleOpts(title="Geo-HeatMap")) return geo
import ssl import pyecharts.options as opts from pyecharts.charts import Map from pyecharts.datasets import register_url """ Gallery 使用 pyecharts 1.1.0 和 echarts-china-cities-js 参考地址: https://echarts.baidu.com/examples/editor.html?c=map-HK """ ssl._create_default_https_context = ssl._create_unverified_context # 与 pyecharts 注册,当画香港地图的时候,用 echarts-china-cities-js register_url("https://echarts-maps.github.io/echarts-china-cities-js") WIKI_LINK = ( "http://zh.wikipedia.org/wiki/" "%E9%A6%99%E6%B8%AF%E8%A1%8C%E6%94%BF%E5%8D%80%E5%8A%83#cite_note-12") MAP_DATA = [ ["中西区", 20057.34], ["湾仔", 15477.48], ["东区", 31686.1], ["南区", 6992.6], ["油尖旺", 44045.49], ["深水埗", 40689.64], ["九龙城", 37659.78], ["黄大仙", 45180.97], ["观塘", 55204.26], ["葵青", 21900.9], ["荃湾", 4918.26], ["屯门", 5881.84], ["元朗", 4178.01], ["北区", 2227.92],
from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.datasets import register_url register_url("https://echarts-maps.github.io/echarts-countries-js/") g = Geo().add_schema(maptype="瑞士").set_global_opts(title_opts=opts.TitleOpts( title="瑞士")) g.render()
def get_day_chart(self, date: str): names, english_names, values, top10_names, top10_values = self.get_one_day_data( date) if sum(values) == 0: raise ZeroDivisionError if self.maptype == 'world': min_data, max_data = 0, max(values) elif self.maptype == 'china-cities': min_data, max_data = 0, 3000 else: min_data, max_data = 0, 5000 data_mark = [0] * len(self.dates) names_ = english_names if self.maptype == 'world' else names if self.maptype == '美国': try: register_url( "https://echarts-maps.github.io/echarts-countries-js/") except Exception: import ssl ssl._create_default_https_context = ssl._create_unverified_context register_url( "https://echarts-maps.github.io/echarts-countries-js/") map_chart = (Map().add( series_name="", data_pair=[list(z) for z in zip(names_, values)], maptype=self.maptype, is_map_symbol_show=False, zoom=1).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts(title_opts=opts.TitleOpts( title=f"{date}: " + self.map_title, pos_left='35%', pos_top="2%", title_textstyle_opts=opts.TextStyleOpts(color='white')), )) line_chart = ( Line().add_xaxis(self.cum_dates).add_yaxis( series_name="", y_axis=self.cum_values, markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max")])).set_series_opts( label_opts=opts.LabelOpts(is_show=False)). set_global_opts( # xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), # yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), title_opts=opts.TitleOpts( title=self.line_title, pos_left="5%", pos_top="2%", title_textstyle_opts=opts.TextStyleOpts(color='white')))) bar_x_data = top10_names[::-1] bar_y_data = [{ "name": name, "value": value } for name, value in zip(top10_names, top10_values)][::-1] 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(axislabel_opts=opts.LabelOpts(is_show=False)), # yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), title_opts=opts.TitleOpts( title=self.bar_title, pos_left="5%", pos_top="50%", title_textstyle_opts=opts.TextStyleOpts(color='white')), tooltip_opts=opts.TooltipOpts(is_show=False), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_right="5%", pos_top="top", range_text=["High", "Low"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=min_data, max_=max_data, ), )) sum_ = sum(values) pie_data = [[name, '%.2f' % (value / sum_)] for name, value in zip(top10_names, top10_values)] rest_value = 1 - sum(top10_values) / sum_ pie_data.append(["其他", '%.2f' % rest_value]) if self.maptype == 'world': center = ["68%", "87%"] pos_left = "62%" pos_top = "65%" elif self.maptype == 'china-cities': center = ["82%", "83%"] pos_left = "76%" pos_top = "65%" elif self.maptype == 'china': center = ["85%", "63%"] pos_left = "80%" pos_top = "43%" else: center = ["85%", "85%"] pos_left = "79%" pos_top = "65%" pie = (Pie().add( series_name="", data_pair=pie_data, radius=["12%", "20%"], center=center, itemstyle_opts=opts.ItemStyleOpts(border_width=1, border_color="rgba(0,0,0,0.3)"), ).set_global_opts( title_opts=opts.TitleOpts( title=self.pie_title, pos_left=pos_left, pos_top=pos_top, title_textstyle_opts=opts.TextStyleOpts(color='white')), tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {c}%"), legend_opts=opts.LegendOpts(is_show=False), ).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))) grid_chart = (Grid(init_opts=opts.InitOpts(page_title=date)).add( bar, grid_opts=opts.GridOpts(pos_left="10", pos_right="80%", pos_top="55%", pos_bottom="1%"), ).add( line_chart, grid_opts=opts.GridOpts(pos_left="10", pos_right="80%", pos_top="10%", pos_bottom="55%"), ).add(pie, grid_opts=opts.GridOpts()).add( map_chart, grid_opts=opts.GridOpts(pos_left="50%"))) return grid_chart
from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.datasets import register_url register_url("https://echarts-maps.github.io/The-Forbidden-City-Demo") g = (Geo().add_schema(maptype="The Forbidden City").set_global_opts( title_opts=opts.TitleOpts(title="The Forbidden City in Beijing"), )) g.render()
def geo_echart_china_js(): register_url("https://echarts-maps.github.io/echarts-china-counties-js/") geo = (Geo().add_schema(maptype="海淀区").set_global_opts( title_opts=opts.TitleOpts(title="海淀区"))) geo.render()