コード例 #1
0
def display_recent_global_distribution(pic_file, maxCount=200, **kwargs):
    """
    display the distribution of recent total numbers of confirmed patients.

    Parameters
    ----------
    pic_file: str
        absolute path of the generated figure.
    maxCount: int
        maximumn count of colorbar. (default: 200)
    """

    conn = db.connect(dbFile)
    cu = conn.cursor()

    OverallDf = pd.read_sql_query("""select * from Region_Data""", conn)
    OverallDf['updateTime'] = OverallDf['updateTime'].astype('int64')

    recentData = OverallDf.groupby('provinceShortName').apply(
        lambda t: t[t['updateTime'] == t['updateTime'].max()])

    recentData = recentData.groupby('country').agg({
        'confirmedCount': 'sum',
        'suspectedCount': 'sum',
        'updateTime': 'mean'
    })
    recentData['date'] = pd.to_datetime(recentData['updateTime'] / 1000,
                                        unit='s')

    time = recentData[recentData.index == '中国']['updateTime']
    data = [[
        searchCountryENName(recentData.index[i]),
        int(recentData['confirmedCount'][i])
    ] for i in range(recentData.shape[0])]

    map_3 = Map()
    map_3.add("{0} worldwide COVID-19 patients distribution".format(
        recentData['date'][1].strftime('%Y-%m-%d')),
              data,
              maptype='world',
              is_map_symbol_show=False)
    map_3.set_series_opts(
        label_opts=opts.LabelOpts(is_show=False, font_size=100))
    map_3.set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=maxCount),
                          title_opts=opts.TitleOpts(title=""))

    if 'notebook' in kwargs.keys():
        if kwargs['notebook']:
            map_3.render_notebook()
    else:
        html_file = '{0}.html'.format(os.path.splitext(pic_file)[0])
        tmpHtmlFile = map_3.render()
        shutil.move(tmpHtmlFile, html_file)
        make_snapshot(snapshot,
                      file_name=html_file,
                      output_name=pic_file,
                      is_remove_html=False,
                      **kwargs)
コード例 #2
0
def display_recent_overall_distribution(pic_file, maxCount=500, **kwargs):
    """
    display the distribution of recent total numbers of nation-wide confirmed
    patients in China.

    Parameters
    ----------
    pic_file: str
        absolute path of the generated figure.
    maxCount: int
        maximumn count of colorbar. (default: 500)
    """

    conn = db.connect(dbFile)
    cu = conn.cursor()
    cu.execute("""select provinceShortName, confirmedCount
        from Region_Data
        where updateTime in (select max(updateTime)
        from Region_Data r_d
        where r_d.country='中国' and r_d.region_id=Region_Data.region_id)
        group by Region_Data.region_id;
        """)
    recentProvinceData = cu.fetchall()

    cu.execute("""select max(updateTime) from Region_Data;""")
    recentTime = cu.fetchone()
    recentTimeObj = dt.datetime.utcfromtimestamp(int(recentTime[0]) / 1000)

    # color-plot
    list1 = [[recentProvinceData[i][0], recentProvinceData[i][1]]
             for i in range(len(recentProvinceData))]
    map_1 = Map()
    map_1.add("{0}全国各省感染总人数".format(recentTimeObj.strftime('%y-%m-%d')),
              list1,
              maptype="china",
              is_map_symbol_show=False)
    map_1.set_global_opts(title_opts=opts.TitleOpts(
        title="{0}全国各省感染总人数".format(recentTimeObj.strftime('%y-%m-%d'))),
                          visualmap_opts=opts.VisualMapOpts(max_=maxCount))

    if 'notebook' in kwargs.keys():
        if kwargs['notebook']:
            map_1.render_notebook()
    else:
        html_file = '{0}.html'.format(os.path.splitext(pic_file)[0])
        tmpHtmlFile = map_1.render()
        shutil.move(tmpHtmlFile, html_file)
        make_snapshot(snapshot,
                      file_name=html_file,
                      output_name=pic_file,
                      is_remove_html=False,
                      **kwargs)
コード例 #3
0
def display_recent_provincial_distribution(province,
                                           pic_file,
                                           maxCount=500,
                                           **kwargs):
    """
    display the distribution of recent total numbers of confirmed patients.

    Parameters
    ----------
    province: str
        province name. e.g., '湖北省'
    pic_file: str
        absolute path of the generated figure.
    maxCount: int
        maximumn count of colorbar. (default: 500)
    """

    conn = db.connect(dbFile)
    cu = conn.cursor()

    cu.execute("""select max(updateTime) from Region_Data;""")
    recentTime = cu.fetchone()
    recentTimeObj = dt.datetime.utcfromtimestamp(int(recentTime[0]) / 1000)

    cu.execute(
        """select cityName, confirmedCount
        from City_Data
        where City_Data.region_id=
        (select id from Region_Name where Region_Name.name=(?))
        and updateTime in (select max(updateTime)
        from City_Data
        where City_Data.region_id=
        (select id from Region_Name where Region_Name.name=(?)))
        group by City_Data.cityName;""", (province, province))
    hubeiProvinceData = cu.fetchall()

    cu.execute(
        """select provinceShortName from Region_Data
                where Region_Data.provinceName = (?)
            """, (province, ))
    hubeiProvinceShortName = cu.fetchone()
    hubeiProvinceShortName = hubeiProvinceShortName[0]

    list2 = [[
        searchCityLongName(hubeiProvinceData[i][0]), hubeiProvinceData[i][1]
    ] for i in range(len(hubeiProvinceData))]
    map_2 = Map()
    map_2.add("{0} {1}感染人数".format(recentTimeObj.strftime('%y-%m-%d'),
                                   province),
              list2,
              maptype=hubeiProvinceShortName,
              is_map_symbol_show=False)
    map_2.set_global_opts(title_opts=opts.TitleOpts(title="{0} {1}感染人数".format(
        recentTimeObj.strftime('%y-%m-%d'), province)),
                          visualmap_opts=opts.VisualMapOpts(max_=maxCount))

    if 'notebook' in kwargs.keys():
        if kwargs['notebook']:
            map_2.render_notebook()
    else:
        html_file = '{0}.html'.format(os.path.splitext(pic_file)[0])
        tmpHtmlFile = map_2.render()
        shutil.move(tmpHtmlFile, html_file)
        make_snapshot(snapshot,
                      file_name=html_file,
                      output_name=pic_file,
                      is_remove_html=False,
                      **kwargs)
コード例 #4
0
                                              "max": 199999
                                          },
                                          {
                                              "min": 50000,
                                              "max": 99999
                                          },
                                          {
                                              "min": 10000,
                                              "max": 49999
                                          },
                                          {
                                              "max": 9999
                                          },
                                      ]),
    title_opts=opts.TitleOpts(
        title="Covid-19 Worldwide Total Cases",
        subtitle='Till July 03rd,2020',
        pos_left='center',
        padding=0,
        item_gap=2,
        title_textstyle_opts=opts.TextStyleOpts(color='darkblue',
                                                font_weight='bold',
                                                font_family='Courier New',
                                                font_size=30),
        subtitle_textstyle_opts=opts.TextStyleOpts(color='grey',
                                                   font_weight='bold',
                                                   font_family='Courier New',
                                                   font_size=13)),
    legend_opts=opts.LegendOpts(is_show=False))
map_1.render_notebook()
コード例 #5
0
# In[48]:


from pyecharts.charts import Map


# In[49]:


c = Map(init_opts=opts.InitOpts(width='800px', height='750px'))
c.add('',[list(z) for z in zip(province_num.index.tolist(), province_num.values.tolist())], 'china')
c.set_global_opts(title_opts=opts.TitleOpts('调剂信息省份分布地图'), 
                  toolbox_opts=opts.ToolboxOpts(is_show=True), 
                  visualmap_opts=opts.VisualMapOpts(max_=110)) 
c.render_notebook()


# In[51]:


import jieba.analyse #cmd pip install jieba


# In[52]:


txt = df['name'].str.cat()
# 添加关键词
jieba.add_word('材料科学与工程')
コード例 #6
0
ファイル: world.py プロジェクト: SalientView/MapShow
from pyecharts import options as opts
from pyecharts.charts import Map

world_map = Map(init_opts=opts.InitOpts(bg_color="#FFFAFA"))

data = {
    "系列1": [['Denmark', 1], ['Uruguay', 7], ['Canada', 5], ['New Zealand', 27],
            ['Chile', 1], ['France', 2], ['Australia', 57], ['Ireland', 2],
            ['Spain', 2], ['Argentina', 2], ['United States', 2]],
    "系列2": [["China", 105]],
}

world_map.add("系列1", data["系列1"], "world", is_map_symbol_show=False)
world_map.add("系列2", data["系列2"], "world", is_map_symbol_show=False)

world_map.set_series_opts(
    label_opts=opts.LabelOpts(position="right", is_show=False))

world_map.set_global_opts(
    title_opts=opts.TitleOpts(title="世界热力图"),
    visualmap_opts=opts.VisualMapOpts(max_=105, is_piecewise=True),
)

world_map.render_notebook()
コード例 #7
0
#%% Setup
myMap = Map()
myMap.add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())],
          "china")
myMap.set_global_opts(
    title_opts=opts.TitleOpts(title="Map-VisualMap(分段型)"),
    visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True),
)

#%% Setup
#myMap.show_config()
#%%
myMap.render()
#%%
myMap.load_javascript()
myMap.render_notebook()

#%%

from pyecharts.charts import Bar

bar = (Bar().add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋",
                        "袜子"]).add_yaxis("商家A", [5, 20, 36, 10, 75, 90]))
bar.load_javascript()
bar.render()

#%% Setup
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 20, 100)
コード例 #8
0
from pyecharts.charts import Map, Geo
from pyecharts import options as opts

data = [("广东", 10430.03), ("山东", 9579.31), ("河南", 9402.36), ("四川", 8041.82),
        ("江苏", 7865.99), ("河北", 7185.42), ("湖南", 6568.37), ("安徽", 5950.1),
        ("浙江", 5442), ("湖北", 5723.77), ("广西", 4602.66), ("云南", 4596.6),
        ("江西", 4456.74), ("辽宁", 4374.63), ("黑龙江", 3831.22), ("陕西", 3732.74),
        ("山西", 3571.21), ("福建", 3552), ("重庆", 2884), ("贵州", 3476.65),
        ("吉林", 2746.22), ("甘肃", 2557.53), ("内蒙古", 2470.63), ("上海", 2301.391),
        ("台湾", 2316.2), ("新疆", 2181.33), ("北京", 1961.2), ("天津", 1293.82),
        ("海南", 867.15), ("香港", 709.76), ("青海", 562.67), ("宁夏", 630.14),
        ("西藏", 300.21), ("澳门", 55.23)]
map = Map()
map.add("", data, "china")
map.set_global_opts(
    title_opts=opts.TitleOpts(title="各省市人口数",
                              subtitle="数据来源:中国统计年鉴(万人)",
                              pos_right="center",
                              pos_top="5%"),
    visualmap_opts=opts.VisualMapOpts(max_=12000),
)
map.render_notebook()
コード例 #9
0
country=list(map_df["location"])
totalcases=list(map_df["total_cases"])


# In[31]:


list1 = [[country[i],totalcases[i]] for i in range(len(country))] #prepare data for visualization
map_1 = Map(init_opts=opts.InitOpts(width='1000px', height='460px')) #create the map and set the size of the map
map_1.add("Total Confirmed Cases", list1, maptype='world') #add world map
map_1.set_global_opts( #set global config
 visualmap_opts=opts.VisualMapOpts(max_=1100000,    is_piecewise=False),
 legend_opts=opts.LegendOpts(is_show=False), #show legend 
 )
map_1.render_notebook() #show the map 


# # A total of 212 countries displayed on map. The data looks clumsy. We can get rid of countries name to make it more attaractive

# In[32]:


list1 = [[country[i],totalcases[i]] for i in range(len(country))] 
map_1 = Map(init_opts=opts.InitOpts(width='1000px', height='460px')) 
map_1.add("Total Confirmed Cases", 
 list1, maptype='world') 
map_1.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) #remove country names
map_1.set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=1100000,is_piecewise=False),
 legend_opts=opts.LegendOpts(is_show=False))
map_1.render_notebook()