Here are the examples of the python api pyecharts.Geo taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
0
View Source File : geoAnalyse.py
License : GNU General Public License v3.0
Project Creator : ContrapunctusXIV
License : GNU General Public License v3.0
Project Creator : ContrapunctusXIV
def GeoMap(filename = "geo_ana"):
f = open("geo.txt","r",encoding="utf-8")
params = f.readline()
f.close()
place_list = re.findall("[(](.*?)[)]",params)
name_counter_dict = {}
for i in place_list:
name_counter_dict[i.split(",")[0].strip('"').strip("'")] = int(i.split(",")[1].strip("'"))
tempered_name_counter_dict = {}
for key,value in name_counter_dict.items():
if len(key)>2 and (key[-1] == "市" or key[-1] == "省"):
if key[:-1] in tempered_name_counter_dict.keys():
tempered_name_counter_dict[key[:-1]] = tempered_name_counter_dict[key[:-1]] + value
else:
tempered_name_counter_dict[key[:-1]] = value
elif key in ['上合','南山区','翻身','科技园','桃园','光明','大学城','八卦岭','龙华','西乡','华侨城','梧桐山','大冲','沙井','红树湾']:
if "深圳" in tempered_name_counter_dict.keys():
tempered_name_counter_dict["深圳"] = tempered_name_counter_dict["深圳"] + value
else:
tempered_name_counter_dict["深圳"] = value
elif key in ['中关村']:
if "北京" in tempered_name_counter_dict.keys():
tempered_name_counter_dict["北京"] = tempered_name_counter_dict["北京"] + value
else:
tempered_name_counter_dict["北京"] = value
elif key in ['虹桥']:
if "上海" in tempered_name_counter_dict.keys():
tempered_name_counter_dict["上海"] = tempered_name_counter_dict["上海"] + value
else:
tempered_name_counter_dict["上海"] = value
else:
tempered_name_counter_dict[key] = value
name_code_dict = {}
code_name_dict = {}
code_counter_dict = {}
simplified_code_counter_dict = {}
simplified_name_counter_dict = {}
final_data = []
sql = "select code,name from Geodata"
with sqlInit.MysqlInit() as mysql_cur:
mysql_cur.execute(sql)
result = mysql_cur.fetchall()
for row in result:
name_code_dict[row[1]] = row[0]
code_name_dict[row[0]] = row[1]
for key,value in tempered_name_counter_dict.items():
code_counter_dict[name_code_dict[key]] = value
for key,value in code_counter_dict.items():
if len(str(key)) < =4:
simplified_code_counter_dict[key] = value
else:
if int(str(key)[:4]) in simplified_code_counter_dict.keys():
simplified_code_counter_dict[int(str(key)[:4])] = simplified_code_counter_dict[int(str(key)[:4])] + value
else:
simplified_code_counter_dict[int(str(key)[:4])] = value
for key,value in simplified_code_counter_dict.items():
with sqlInit.GeoSqlInit() as sqlite_cur:
if len(str(key))==2:
sql1 = "select name from province where code="+str(key)
fetchResult1 = sqlite_cur.execute(sql1)
for row in fetchResult1:
simplified_name_counter_dict[row[0]] = value
if "自治区" in row[0]:
final_data.append((row[0].strip("自治区"),value))
else:
final_data.append((row[0][:-1],value))
elif len(str(key))==4:
sql2 = "select name from city where code="+str(key)
fetchResult2 = sqlite_cur.execute(sql2)
for row in fetchResult2:
if row[0] == "市辖区":
sql3 = "select name from province where code="+str(key)[:2]
fetchResult3 = sqlite_cur.execute(sql3)
for row2 in fetchResult3:
simplified_name_counter_dict[row2[0]] = value
final_data.append((row2[0],value))
elif row[0] == "襄阳市":
simplified_name_counter_dict[row[0][:-1]] = value
final_data.append((row[0][:-1],value))
else:
simplified_name_counter_dict[row[0]] = value
final_data.append((row[0],value))
data = final_data
geo = Geo(
"",
"",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
attr, value = geo.cast(data)
geo.add(
"",
attr,
value,
visual_range=[0, 200],
visual_text_color="#fff",
symbol_size=15,
type="heatmap",
is_visualmap=True,
maptype='china',
coordinate_region='中国'
)
geo.render(path="./output/"+filename+".html")
geo.render(path="./output/"+filename+".pdf")
print("已生成图")
GeoMap()
0
View Source File : drawer.py
License : MIT License
Project Creator : DQinYuan
License : MIT License
Project Creator : DQinYuan
def echarts_draw(adcodes, file_path, title="地域分布图"
, subtitle="location distribute"):
"""
生成地域分布的echarts热力图的html文件.
:param adcodes: 地址集
:param file_path: 生成的html文件路径.
:param title: 图表的标题
:param subtitle: 图表的子标题
"""
from pyecharts import Geo
# 过滤 None
# 过滤掉缺乏经纬度数据的地点
coordinates = {}
counter = defaultdict(int)
for adcode in filter(None, adcodes):
addr = ad2addr(adcode)
if not addr.longitude or not addr.latitude:
continue
counter[adcode] = counter[adcode] + 1
coordinates[adcode] = (float(addr.longitude), float(addr.latitude))
geo = Geo(title, subtitle, title_color="#fff",
title_pos="center", width=1200,
height=600, background_color='#404a59')
geo._coordinates = coordinates
attr, value = geo.cast(counter)
geo.add("", attr, value, type="heatmap", is_visualmap=True,
visual_text_color='#fff',
is_piecewise=True, visual_split_number=10)
geo.render(file_path)
def echarts_cate_draw(adcodes, labels, file_path, title="地域分布图", subtitle="location distribute",
0
View Source File : drawer.py
License : MIT License
Project Creator : DQinYuan
License : MIT License
Project Creator : DQinYuan
def echarts_cate_draw(adcodes, labels, file_path, title="地域分布图", subtitle="location distribute",
point_size=7):
"""
依据分类生成地域分布的echarts散点图的html文件.
:param adcodes: 地址集
:param labels: 长度必须和locations相等, 代表每个样本所属的分类.
:param file_path: 生成的html文件路径.
:param title: 图表的标题
:param subtitle: 图表的子标题
:param point_size: 每个散点的大小
"""
if len(adcodes) != len(labels):
from .exceptions import CPCAException
raise CPCAException("locations的长度与labels长度必须相等")
# 过滤 None
# 过滤掉缺乏经纬度数据的地点
coordinates = {}
tuples = []
for adcode, label in filter(lambda t: t[0] is not None, zip(adcodes, labels)):
addr = ad2addr(adcode)
if not addr.longitude or not addr.latitude:
continue
coordinates[adcode] = (float(addr.longitude), float(addr.latitude))
tuples.append((adcode, label))
from pyecharts import Geo
geo = Geo(title, subtitle, title_color="#000000",
title_pos="center", width=1200,
height=600, background_color='#fff')
geo._coordinates = coordinates
for label, sub_tuples in itertools.groupby(tuples, operator.itemgetter(1)):
sub_adcodes_list = list(map(operator.itemgetter(0), sub_tuples))
value = [1] * len(sub_adcodes_list)
geo.add(label, sub_adcodes_list, value, symbol_size=point_size,
legend_pos="left", legend_top="bottom",
geo_normal_color="#fff",
geo_emphasis_color=" #f0f0f5")
geo.render(file_path)