def test_map3d_schema(fake_writer): c = (Map3D().add_schema( itemstyle_opts=opts.ItemStyleOpts(), map3d_label=opts.Map3DLabelOpts(), light_opts=opts.Map3DLightOpts(), view_control_opts=opts.Map3DViewControlOpts(), post_effect_opts=opts.Map3DPostEffectOpts(), realistic_material_opts=opts.Map3DRealisticMaterialOpts(), lambert_material_opts=opts.Map3DLambertMaterialOpts(), color_material_opts=opts.Map3DColorMaterialOpts(), ).add( series_name="商家A", data_pair=[list(z) for z in zip(Faker.provinces, Faker.values())], maptype="china", type_=ChartType.LINES3D, effect=opts.Lines3DEffectOpts(), )) c.render() _, content = fake_writer.call_args[0] assert_in("itemStyle", content) assert_in("label", content) assert_in("light", content) assert_in("viewControl", content) assert_in("postEffect", content) assert_in("realisticMaterial", content) assert_in("lambertMaterial", content) assert_in("colorMaterial", content)
def map3d_china_base() -> Map3D: c = (Map3D().add_schema( itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), map3d_label=opts.Map3DLabelOpts( is_show=True, text_style=opts.TextStyleOpts(color="#fff", font_size=16, background_color="rgba(0,0,0,0)"), ), emphasis_label_opts=opts.LabelOpts(is_show=True), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, is_main_shadow=False, main_alpha=55, main_beta=10, ambient_intensity=0.3, ), ).add(series_name="", data_pair="", maptype=ChartType.MAP3D).set_global_opts( title_opts=opts.TitleOpts(title="全国行政区划地图-Base"), visualmap_opts=opts.VisualMapOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True), )) return c
def test_map_3d(fake_writer): c = Map3D().add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china") c.render() _, content = fake_writer.call_args[0] assert_in("map3D", content) assert_equal(c.theme, "white") assert_equal(c.renderer, "canvas")
def test_map3d_base(fake_writer): c = (Map3D().add_schema().add( "商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], maptype="china", )) c.render() _, content = fake_writer.call_args[0] assert_in("map3D", content)
def generate_3d_map(self, provinces_data): map_3d = Map3D(init_opts=opts.InitOpts(width="1280px", height="720px")) map_3d.add_schema( itemstyle_opts=opts.ItemStyleOpts( color="#172eb2", opacity=1, border_width=0.8, border_color="rgb(76, 96, 255)", ), map3d_label=opts.Map3DLabelOpts( is_show=False, formatter=JsCode("function(data){return data.name + " " + data.value[2];}"), ), emphasis_label_opts=opts.LabelOpts( is_show=False, color="#fff", font_size=10, background_color="rgba(242, 149, 128, 0)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, main_shadow_quality="high", is_main_shadow=True, main_beta=10, ambient_intensity=0.3, ), is_show_ground=True, ground_color="#FFF", ) map_3d_data = [] from .data import provinces_coordinates for item in provinces_data.items(): province_data = (item[0], [*provinces_coordinates[item[0]], item[1]]) map_3d_data.append(province_data) map_3d.add( series_name="Data", data_pair=map_3d_data, type_=ChartType.BAR3D, bar_size=1, itemstyle_opts=opts.ItemStyleOpts(color="rgb(173, 212, 217)"), shading="realistic", label_opts=opts.LabelOpts( is_show=False, formatter=JsCode( "function(data){return data.name + ' ' + data.value[2];}"), ), ) map_3d.set_global_opts(title_opts=opts.TitleOpts(title="3D Map")) map_3d.render("map3d_with_bar3d.html")
def to_map_3D_china(self,data,update_time): c = ( Map3D(init_opts=opts.InitOpts(width='1200px',height='800px')) .add_schema( itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), map3d_label=opts.Map3DLabelOpts( is_show=False, formatter=JsCode("function(data){return data.name + " " + data.value[2];}"), ), emphasis_label_opts=opts.LabelOpts( is_show=False, color="#fff", font_size=10, background_color="rgba(0,23,11,0)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, main_shadow_quality="high", is_main_shadow=False, main_beta=10, ambient_intensity=0.3, ), ) .add( series_name="中国3D疫情图", data_pair=list(zip(list(data.keys()), list(data.values()))), type_=ChartType.SCATTER3D, bar_size=1, shading="lambert", label_opts=opts.LabelOpts( is_show=True, formatter=JsCode("function(data){return data.name + ' ' + data.value[2];}"), ), ) .set_global_opts( title_opts=opts.TitleOpts(title="中国疫情3D地图分布", subtitle="截止%s 中国疫情分布情况" % (update_time), pos_left='center', pos_top='30px') ) .render("map3d_中国疫情地图.html") )
def map3d_with_lines3d() -> Map3D: example_data = [ [[119.107078, 36.70925, 1000], [116.587245, 35.415393, 1000]], [[117.000923, 36.675807], [120.355173, 36.082982]], [[118.047648, 36.814939], [118.66471, 37.434564]], [[121.391382, 37.539297], [119.107078, 36.70925]], [[116.587245, 35.415393], [122.116394, 37.509691]], [[119.461208, 35.428588], [118.326443, 35.065282]], [[116.307428, 37.453968], [115.469381, 35.246531]], ] c = (Map3D().add_schema( maptype="山东", itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, is_main_shadow=False, main_alpha=55, main_beta=10, ambient_intensity=0.3, ), view_control_opts=opts.Map3DViewControlOpts(center=[-10, 0, 10]), post_effect_opts=opts.Map3DPostEffectOpts(is_enable=False), ).add( series_name="", data_pair=example_data, type_=ChartType.LINES3D, effect=opts.Lines3DEffectOpts( is_show=True, period=4, trail_width=3, trail_length=0.5, trail_color="#f00", trail_opacity=1, ), linestyle_opts=opts.LineStyleOpts(is_show=False, color="#fff", opacity=0), ).set_global_opts(title_opts=opts.TitleOpts(title="Map3D-Lines3D"))) return c
Map3D(init_opts=opts.InitOpts( theme=ThemeType.DARK, bg_color='#404a59', width='1600px', height='900px' )) .add_schema( itemstyle_opts=opts.ItemStyleOpts( color="#313c48", opacity=1, border_width=0.8, border_color="#fff", ), map3d_label=opts.Map3DLabelOpts( is_show=True, text_style=opts.TextStyleOpts( color="#fff", font_size=16, background_color="rgba(0,0,0,0)" ), ), emphasis_label_opts=opts.LabelOpts(is_show=True), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, is_main_shadow=False, main_alpha=55, main_beta=10, ambient_intensity=0.3, ), ) .add(series_name="", data_pair="", maptype=ChartType.MAP3D) .set_global_opts( title_opts=opts.TitleOpts(title="全国行政区划地图"), visualmap_opts=opts.VisualMapOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True), ) .render("map3d_china.html")
c = (Map3D().add_schema( itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), map3d_label=opts.Map3DLabelOpts( is_show=False, formatter=JsCode("function(data){return data.name + " " + data.value[2];}"), ), emphasis_label_opts=opts.LabelOpts( is_show=False, color="#fff", font_size=10, background_color="rgba(0,23,11,0)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, main_shadow_quality="high", is_main_shadow=False, main_beta=10, ambient_intensity=0.3, ), ).add( series_name="Scatter3D", data_pair=example_data, type_=ChartType.SCATTER3D, bar_size=1, shading="lambert", label_opts=opts.LabelOpts( is_show=False, formatter=JsCode( "function(data){return data.name + ' ' + data.value[2];}"), ), ).set_global_opts(title_opts=opts.TitleOpts( title="Map3D-Scatter3D")).render("map3d_with_scatter3d.html"))
Map3D().add_schema( box_height=15, region_height=2, # is_show_ground = True, shading="lambert", itemstyle_opts=opts.ItemStyleOpts( color="rgb(169,169,169)", opacity=1, border_width=0.8, border_color="rgb(245,245,245)", ), map3d_label=opts.Map3DLabelOpts( is_show=False, formatter=JsCode("function(data){return data.name + " " + data.value[2];}"), ), emphasis_label_opts=opts.LabelOpts( is_show=False, color="#fff", font_size=10, background_color="rgba(0,23,11,0)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, main_shadow_quality="high", is_main_shadow=False, main_beta=10, ambient_intensity=0.3, ), ).add( series_name="bar3D", data_pair=[ list(z) for z in zip(ElectricityData.provinces, ElectricityData.Geo2017) ], type_=ChartType.BAR3D, is_map_symbol_show=True, bar_size=1.5, shading="lambert", bevel_size=0.2, label_opts=opts.LabelOpts( is_show=True, formatter=JsCode("function(data){return data.value[2];}"), font_size=1, ), min_height=0.5, ).set_global_opts(title_opts=opts.TitleOpts(title="ElectricityProduction"), visualmap_opts=opts.VisualMapOpts( max_=5000, range_color=[ "#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf", "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026", ], )).render("2017_3D.html"))
c = (Map3D().add_schema( maptype="山东", itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, is_main_shadow=False, main_alpha=55, main_beta=10, ambient_intensity=0.3, ), view_control_opts=opts.Map3DViewControlOpts(center=[-10, 0, 10]), post_effect_opts=opts.Map3DPostEffectOpts(is_enable=False), ).add( series_name="", data_pair=example_data, type_=ChartType.LINES3D, effect=opts.Lines3DEffectOpts( is_show=True, period=4, trail_width=3, trail_length=0.5, trail_color="#f00", trail_opacity=1, ), linestyle_opts=opts.LineStyleOpts(is_show=False, color="#fff", opacity=0), ).set_global_opts(title_opts=opts.TitleOpts( title="Map3D-Lines3D")).render("Map3d_with_lines3d.html"))
Map3D(init_opts=opts.InitOpts(width='1500px',height='1000px',bg_color='#EBEBEB')) #设置地图大小及颜色 .add_schema( itemstyle_opts=opts.ItemStyleOpts( color = '#CDBA96', opacity= 1, border_width=0.8, border_color="rgd(62,215,213)", ), map3d_label=opts.Map3DLabelOpts( is_show=True, text_style=opts.TextStyleOpts( color="#CEF9F4",font_size=16,background_color="rgba(0,0,0)" ), ), emphasis_label_opts=opts.LabelOpts(is_show=True), #地图整体颜色 light_opts=opts.Map3DLightOpts( main_color="#FFEBCD", main_intensity=1.2, main_alpha=55, main_beta=10, ambient_intensity=0.3 ), ) .add(series_name="",data_pair="",maptype=ChartType.MAP3D) .set_global_opts( #全局设置地图属性 title_opts=opts.TitleOpts(title="全国行政区划分图"), visualmap_opts=opts.VisualMapOpts(is_show=True), tooltip_opts=opts.TooltipOpts(is_show=False), ) .render("HTML/map3d_china_base.html")
def Map_CT() -> Map3D: example_data = [ ("黑龙江", [127.9688, 45.368, 100]), ("内蒙古", [110.3467, 41.4899, 100]), ("吉林", [125.8154, 44.2584, 100]), ("辽宁", [123.1238, 42.1216, 100]), ("河北", [114.4995, 38.1006, 100]), ("天津", [117.4219, 39.4189, 100]), ("山西", [112.3352, 37.9413, 100]), ("陕西", [109.1162, 34.2004, 100]), ("甘肃", [103.5901, 36.3043, 100]), ("宁夏", [106.3586, 38.1775, 100]), ("青海", [101.4038, 36.8207, 100]), ("新疆", [87.9236, 43.5883, 100]), ("西藏", [91.11, 29.97, 100]), ("四川", [103.9526, 30.7617, 100]), ("重庆", [108.384366, 30.439702, 100]), ("山东", [117.1582, 36.8701, 100]), ("河南", [113.4668, 34.6234, 100]), ("江苏", [118.8062, 31.9208, 100]), ("安徽", [117.29, 32.0581, 100]), ("湖北", [114.3896, 30.6628, 100]), ("浙江", [119.5313, 29.8773, 100]), ("福建", [119.4543, 25.9222, 100]), ("江西", [116.0046, 28.6633, 100]), ("湖南", [113.0823, 28.2568, 100]), ("贵州", [106.6992, 26.7682, 100]), ("广西", [108.479, 23.1152, 100]), ("海南", [110.3893, 19.8516, 100]), ("上海", [121.4648, 31.2891, 100]), ] c = ( Map3D().add_schema( itemstyle_opts=opts.ItemStyleOpts( color="rgb(5,101,123)", opacity=1, border_width=0.8, border_color="rgb(62,215,213)", ), map3d_label=opts.Map3DLabelOpts( is_show=False, formatter=JsCode("function(data){return data.name + " " + data.value[2];}"), ), emphasis_label_opts=opts.LabelOpts( is_show=False, color="#fff", font_size=10, background_color="rgba(0,23,11,0)", ), light_opts=opts.Map3DLightOpts( main_color="#fff", main_intensity=1.2, main_shadow_quality="high", is_main_shadow=False, main_beta=10, ambient_intensity=0.3, ), ).add( series_name="XX换流站", data_pair=example_data, type_=ChartType.SCATTER3D, bar_size=1, shading="lambert", label_opts=opts.LabelOpts( is_show=False, formatter=JsCode( "function(data){return data.name + ' ' + data.value[2];}" ), ), ).set_global_opts(title_opts=opts.TitleOpts( title="Map3D-Scatter3D")) # .render("map3d_with_scatter3d.html") ) return c
from pyecharts.charts import Map3D Map3D().add_schema().render()