예제 #1
0
def test_full_example():
    data = [("广州", 45), ("漳州", 35), ("A市", 43)]
    geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
    coordinate = geo.get_coordinate("广州")
    assert 2 == len(coordinate)
    with assert_raises(ValueError):
        geo.get_coordinate("A市", raise_exception=True)
    attr, value = geo.cast(data)
    with assert_raises(ValueError):
        geo.add(
            "",
            attr,
            value,
            type="effectScatter",
            is_random=True,
            is_visualmap=True,
            is_piecewise=True,
            visual_text_color="#fff",
            pieces=[
                {"min": 0, "max": 13, "label": "0 < x < 13"},
                {"min": 14, "max": 16, "label": "14 < x < 16"},
            ],
            effect_scale=5,
        )
    geo.add_coordinate("A市", 119.3, 26.08)
    geo.add(
        "",
        attr,
        value,
        type="effectScatter",
        is_random=True,
        is_visualmap=True,
        is_piecewise=True,
        visual_text_color="#fff",
        pieces=[
            {"min": 0, "max": 13, "label": "0 < x < 13"},
            {"min": 14, "max": 16, "label": "14 < x < 16"},
        ],
        effect_scale=5,
    )
    geo.render()
예제 #2
0
import json
from pyecharts import Geo

author_locations_file = './db/author_locations.json'
with open(author_locations_file, 'r', encoding='utf-8') as file_obj:
  author_locations = json.load(file_obj)


author = '杜甫'

locations = [location for location in author_locations[author] if location != []] 
location_names = [location[0] for location in locations]

geo = Geo(author + '足迹图', title_pos='center', title_top='top', title_text_size=15, width=700, height=700)
for location in locations:
  geo.add_coordinate(location[0], location[3], location[2])

geo.add('', location_names, range(len(locations)), maptype='china', geo_normal_color='white', 
    geo_emphasis_color='skyblue', symbol_size=7, is_visualmap=True, is_label_show=False, 
    label_text_color='black', label_text_size=7, label_formatter='{b}')

geo.add("",
        location_names, range(len(locations), maptype="china", geo_normal_color='white', geo_emphasis_color='skyblue', symbol_size=7,
        is_visualmap=False, 
        is_label_show=True,
        label_text_color='black',
        label_text_size=7,
        label_formatter='{b}')         
geo.render("dufu.html") 

예제 #3
0
from pyecharts import Geo

data = [('广州', 45), ('漳州', 135), ('A市', 43), ('郑州', 200), ('商城', 5)]
# geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
# geo = Geo("全国主要城市空气质量", "data from pm2.5")

geo = Geo("全国主要城市空气质量",
          "data from pm2.5",
          title_color="#fff",
          title_pos="center",
          width=800,
          height=400,
          background_color='#404a59')
attr, value = geo.cast(data)
geo.add_coordinate("商城", 115.42, 31.81)  # 数据仅供示例/
geo.add_coordinate('A市', 119.3, 26.08)  # 添加 pyecharts 未提供的城市地理坐标
geo.add(
    "全国主要城市空气质量",
    attr,
    value,
    type="effectScatter",
    is_random=True,
    is_visualmap=True,
    is_piecewise=True,
    # symbol_size=10,
    # maptype='china',
    visual_text_color="#fff",
    pieces=[
        {
            "min": 0,
            "max": 50,