You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from pyecharts.charts import Map
from pyecharts import options as opts
import pandas as pd
from getData import getData
def map():
getData()
data = pd.read_csv('北京市区房价.csv',encoding='utf-8')
info = data[['行政区','均价(元/㎡)']].copy()
# 移除千分号转换为浮点数然后四舍五入到最接近的整数或者直接使用astype(int)向下取整)
info['均价(元/㎡)'] = info['均价(元/㎡)'].str.replace(',', '').astype(float).round().astype(int)
info_list = info.values.tolist()
print(info_list)
map=Map(
init_opts=opts.InitOpts(
page_title="地图"
)
)
map.add(
series_name="平均房价",
data_pair=info_list,
maptype="北京",
zoom=1,
)
map.set_global_opts(
title_opts=opts.TitleOpts(
title="北京市市区",
pos_left='center',
),
legend_opts=opts.LegendOpts(
pos_left="left", # 图例在左边
orient="vertical" # 垂直排列图例
),
visualmap_opts=opts.VisualMapOpts(
max_=130000,
min_=19000,
range_color=['#1E9600','#fff200','#ff0000']
)
)
map.render('map.html')