first commit

main
Zeng Jia Hua 6 months ago
parent b80b59d9bc
commit 8235bc1346

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (pythonProject1)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject1)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject1.iml" filepath="$PROJECT_DIR$/.idea/pythonProject1.iml" />
</modules>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,204 @@
import tkinter as tk
import webbrowser
from tkinter import ttk, messagebox
import pandas as pd
import requests
from lxml import etree
from map import map
from line import line
class Home():
def __init__(self):
self.root = tk.Tk()
self.root.title("购房推荐系统")
self.root.geometry("650x350+500+200")
self.Max_index = ''
self.Current_index = 1
# 把爬取的三条信息组成一个元组捆绑,变成一条记录
self.all_info = []
self.text=''
self.label = tk.Label(self.root, text="欢迎来到北京市购房推荐系统,请选择要查询的地区", font=('宋体', 20), background="#00ffff")
self.label.grid(row=0, column=0, columnspan=4, pady=(20, 0))
self.button_texts = ["海淀", "朝阳", "丰台", "西城", "东城", "昌平", "大兴", "通州", "房山", "顺义", "石景山",
"密云"]
for i, text in enumerate(self.button_texts):
self.button = tk.Button(self.root, text=text, command=lambda txt=text: self.on_button_click(txt))
row = i // 4 + 1
col = i % 4
self.button.grid(row=row, column=col, padx=10, pady=10)
self.btn_map=tk.Button(self.root,text='区位房价',command=self.open_map)
self.btn_map.place(relx=0.65, rely=0.8, relheight=0.10, relwidth=0.13)
self.btn_line=tk.Button(self.root,text="同比房价",command=self.open_line)
self.btn_line.place(relx=0.2, rely=0.8, relheight=0.10, relwidth=0.13)
self.root.mainloop()
def open_map(self):
map()
webbrowser.open('map.html')
self.clear_csv()
def open_line(self):
line()
webbrowser.open('line.html')
self.clear_csv()
#爬取数据并做匹配
def fetch_data(self,region, index='1'):
url = f"https://newhouse.fang.com/house/s/{region}/b9"+index
response = requests.get(url)
response.encoding = "utf-8"
e = etree.HTML(response.text)
names = [n.strip() for n in e.xpath('//div[@class="nlcd_name"]/a/text()')]
addresses = e.xpath('//div[@class="address"]/a/@title')
prices = [d.xpath('string(.)').strip() for d in e.xpath('//div[@class="nhouse_price"]')]
if index=='1' and self.Max_index=='':
lasts = e.xpath('//a[@class="last"]/@href')
if len(lasts)!=0:
the_string = lasts[-1]
last_char = the_string[-2]
self.Max_index = str(last_char)
else:
return 'False'
for name, address, price in zip(names, addresses, prices):
self.all_info.append((name, price, address))
return self.all_info
# 展示图表数据函数
def show_data_in_table(self,data):
self.popup = tk.Toplevel(self.root)
self.popup.geometry('500x500')
self.popup.title("购房信息详情")
# 使用pandas DataFrame处理数据
df = pd.DataFrame(data, columns=["楼盘名称", "价格", "地区"])
# 创建Treeview部件显式指定列ID
tree = ttk.Treeview(self.popup, columns=("name", "price", "area"), show="headings")
# 设置列标题使用之前定义的列ID
tree.heading("#1", text="楼盘名称")
tree.heading("#2", text="价格")
tree.heading("#3", text="地区")
# 设置列宽度
tree.column("#1", width=100, anchor='center')
tree.column("#2", width=100, anchor='center')
tree.column("#3", width=100, anchor='center')
# 将DataFrame数据插入Treeview
for index, row in df.iterrows():
tree.insert('', 'end', values=row.tolist())
# 添加垂直滚动条
vsb = ttk.Scrollbar(self.popup, orient="vertical", command=tree.yview)
tree.configure(yscrollcommand=vsb.set)
vsb.pack(side='right', fill='y')
tree.pack(fill='both', expand=True)
# 添加底部框架用于放置翻页按钮
footer_frame = ttk.Frame(self.popup)
footer_frame.pack(side='bottom', fill='x')
footer_frame = ttk.Frame(self.popup)
footer_frame.pack(side='bottom', fill='x')
# 上一页按钮
prev_button = ttk.Button(footer_frame, text="上一页", command=self.go_to_previous_page)
prev_button.pack(side='left', padx=5, pady=5)
# 下一页按钮
next_button = ttk.Button(footer_frame, text="下一页", command=self.go_to_next_page)
next_button.pack(side='right', padx=5, pady=5)
self.center_window()
# 上翻页函数
def go_to_previous_page(self):
if self.Current_index+90 -1 >=91:
self.popup.destroy()
self.Current_index -= 1
print(self.Current_index)
self.all_info.clear()
# 把选择的区域 传入通过fetch传入url
data = self.fetch_data(self.text, str(self.Current_index))
# 网页地址传给展示页面
self.show_data_in_table(data)
else:
messagebox.showinfo(message='这是第一页')
# 下翻页函数
def go_to_next_page(self):
if self.Current_index + 1 <= int(self.Max_index):
self.popup.destroy()
self.Current_index += 1
print(self.Current_index)
self.all_info.clear()
# 把选择的区域 传入通过fetch传入url
data = self.fetch_data(self.text, str(self.Current_index))
# 网页地址传给展示页面
self.show_data_in_table(data)
else:
messagebox.showinfo(message='末尾')
# 首页点击函数
def on_button_click(self,text, index='1'):
self.Max_index = ''
self.Current_index = 1
self.all_info = []
self.text = ''
simplified_text = {
"海淀": "haidian",
"朝阳": "chaoyang",
"丰台": "fengtai",
"西城": "xicheng",
"东城": "dongcheng",
"昌平": "changping",
"大兴": "daxing",
"通州": "tongzhou",
"房山": "fangshan",
"顺义": "shunyi",
"石景山": "shijingshan",
"密云": "miyun",
}.get(text, "未知区域")
self.text=text
# 把选择的区域 传入通过fetch传入url
if self.fetch_data(simplified_text, index)!="False":
data = self.fetch_data(simplified_text, index)
# 网页地址传给展示页面
self.show_data_in_table(data)
else:
messagebox.showinfo(message='该地区暂无数据!')
def center_window(self, width=1200, height=600):
# 获取屏幕宽度和高度
screen_width = self.popup.winfo_screenwidth()
screen_height = self.popup.winfo_screenheight()
# 计算窗口的左上角应该放置的位置
left = (screen_width / 2) - (width / 2)
top = (screen_height / 2) - (height / 2)
# 设置窗口的位置和大小
self.popup.geometry("{0}x{1}+{2}+{3}".format(width, height, int(left), int(top)))
def clear_csv(self):
with open('北京市区房价.csv', 'w', encoding='utf-8', newline=''):
pass

@ -0,0 +1,5 @@
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

@ -0,0 +1,33 @@
import csv
import requests
from bs4 import BeautifulSoup
def getData():
url='https://bj.cityhouse.cn/market/rankforsale.html'
headers={
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Content-Type':'text/html; charset=utf-8',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0'
}
response=requests.get(url=url,headers=headers)
soup = BeautifulSoup(response.text, 'lxml')
tbody=soup.find('tbody')
Ver_index=len(tbody.findAll('tr'))
Ori_index=len(tbody.findAll('tr')[0].findAll('th'))
with open('北京市区房价.csv','a',encoding='utf-8',newline='') as f:
write=csv.writer(f)
for i in range(Ver_index):
list=[]
if i==0:
for j in range(Ori_index):
list.append(tbody.findAll('tr')[i].findAll('th')[j].text.strip())
else:
for j in range(Ori_index):
list.append(tbody.findAll('tr')[i].findAll('td')[j].text.strip())
write.writerow(list)
print('shu数据获取完毕')
if __name__ == '__main__':
getData()

@ -0,0 +1,424 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>多折线</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
</head>
<body >
<div id="230081edc72b4d1bb7f50f04c025a37b" class="chart-container" style="width:1000px; height:500px; "></div>
<script>
var chart_230081edc72b4d1bb7f50f04c025a37b = echarts.init(
document.getElementById('230081edc72b4d1bb7f50f04c025a37b'), 'white', {renderer: 'canvas'});
var option_230081edc72b4d1bb7f50f04c025a37b = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"aria": {
"enabled": false
},
"color": [
"#5470c6",
"#91cc75",
"#fac858",
"#ee6666",
"#73c0de",
"#3ba272",
"#fc8452",
"#9a60b4",
"#ea7ccc"
],
"series": [
{
"type": "line",
"name": "\u73af\u6bd4\u4e0a\u6708",
"connectNulls": false,
"xAxisIndex": 0,
"symbolSize": 4,
"showSymbol": true,
"smooth": false,
"clip": true,
"step": false,
"data": [
[
"\u660c\u5e73\u533a",
1.41
],
[
"\u671d\u9633\u533a",
-2.98
],
[
"\u5927\u5174\u533a",
-6.43
],
[
"\u4e1c\u57ce\u533a",
1.08
],
[
"\u623f\u5c71\u533a",
-2.01
],
[
"\u4e30\u53f0\u533a",
0.83
],
[
"\u6d77\u6dc0\u533a",
1.47
],
[
"\u6000\u67d4\u533a",
-3.15
],
[
"\u95e8\u5934\u6c9f\u533a",
-3.41
],
[
"\u5bc6\u4e91\u533a",
-2.92
],
[
"\u5e73\u8c37\u533a",
1.3
],
[
"\u77f3\u666f\u5c71\u533a",
-2.23
],
[
"\u987a\u4e49\u533a",
-6.78
],
[
"\u901a\u5dde\u533a",
-1.98
],
[
"\u897f\u57ce\u533a",
0.13
],
[
"\u5ef6\u5e86\u533a",
3.0
]
],
"hoverAnimation": true,
"label": {
"show": true,
"margin": 8
},
"logBase": 10,
"seriesLayoutBy": "column",
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
},
"areaStyle": {
"opacity": 0
},
"zlevel": 0,
"z": 0
},
{
"type": "line",
"name": "\u540c\u6bd4\u4e0a\u5e74",
"connectNulls": false,
"xAxisIndex": 0,
"symbolSize": 4,
"showSymbol": true,
"smooth": false,
"clip": true,
"step": false,
"data": [
[
"\u660c\u5e73\u533a",
-4.81
],
[
"\u671d\u9633\u533a",
-9.58
],
[
"\u5927\u5174\u533a",
-6.72
],
[
"\u4e1c\u57ce\u533a",
-6.47
],
[
"\u623f\u5c71\u533a",
-6.53
],
[
"\u4e30\u53f0\u533a",
-5.3
],
[
"\u6d77\u6dc0\u533a",
-5.78
],
[
"\u6000\u67d4\u533a",
-6.3
],
[
"\u95e8\u5934\u6c9f\u533a",
-7.0
],
[
"\u5bc6\u4e91\u533a",
-13.3
],
[
"\u5e73\u8c37\u533a",
-1.14
],
[
"\u77f3\u666f\u5c71\u533a",
-3.57
],
[
"\u987a\u4e49\u533a",
-13.6
],
[
"\u901a\u5dde\u533a",
-7.68
],
[
"\u897f\u57ce\u533a",
-4.71
],
[
"\u5ef6\u5e86\u533a",
-5.85
]
],
"hoverAnimation": true,
"label": {
"show": true,
"margin": 8
},
"logBase": 10,
"seriesLayoutBy": "column",
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
},
"areaStyle": {
"opacity": 0
},
"zlevel": 0,
"z": 0
}
],
"legend": [
{
"data": [
"\u73af\u6bd4\u4e0a\u6708",
"\u540c\u6bd4\u4e0a\u5e74"
],
"selected": {},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14,
"backgroundColor": "transparent",
"borderColor": "#ccc",
"borderRadius": 0,
"pageButtonItemGap": 5,
"pageButtonPosition": "end",
"pageFormatter": "{current}/{total}",
"pageIconColor": "#2f4554",
"pageIconInactiveColor": "#aaa",
"pageIconSize": 15,
"animationDurationUpdate": 800,
"selector": false,
"selectorPosition": "auto",
"selectorItemGap": 7,
"selectorButtonGap": 10
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"enterable": false,
"confine": false,
"appendToBody": false,
"transitionDuration": 0.4,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5,
"order": "seriesAsc"
},
"xAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"data": [
"\u660c\u5e73\u533a",
"\u671d\u9633\u533a",
"\u5927\u5174\u533a",
"\u4e1c\u57ce\u533a",
"\u623f\u5c71\u533a",
"\u4e30\u53f0\u533a",
"\u6d77\u6dc0\u533a",
"\u6000\u67d4\u533a",
"\u95e8\u5934\u6c9f\u533a",
"\u5bc6\u4e91\u533a",
"\u5e73\u8c37\u533a",
"\u77f3\u666f\u5c71\u533a",
"\u987a\u4e49\u533a",
"\u901a\u5dde\u533a",
"\u897f\u57ce\u533a",
"\u5ef6\u5e86\u533a"
]
}
],
"yAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
}
}
],
"title": [
{
"show": true,
"text": "\u5317\u4eac\u5e02\u533a\u623f\u4ef7\u8d8b\u52bf\u56fe",
"target": "blank",
"subtarget": "blank",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
],
"toolbox": {
"show": true,
"orient": "horizontal",
"itemSize": 15,
"itemGap": 10,
"left": "80%",
"feature": {
"saveAsImage": {
"type": "png",
"backgroundColor": "auto",
"connectedBackgroundColor": "#fff",
"show": true,
"title": "\u4fdd\u5b58\u4e3a\u56fe\u7247",
"pixelRatio": 1
},
"restore": {
"show": true,
"title": "\u8fd8\u539f"
},
"dataView": {
"show": true,
"title": "\u6570\u636e\u89c6\u56fe",
"readOnly": false,
"lang": [
"\u6570\u636e\u89c6\u56fe",
"\u5173\u95ed",
"\u5237\u65b0"
],
"backgroundColor": "#fff",
"textareaColor": "#fff",
"textareaBorderColor": "#333",
"textColor": "#000",
"buttonColor": "#c23531",
"buttonTextColor": "#fff"
},
"dataZoom": {
"show": true,
"title": {
"zoom": "\u533a\u57df\u7f29\u653e",
"back": "\u533a\u57df\u7f29\u653e\u8fd8\u539f"
},
"icon": {},
"filterMode": "filter"
},
"magicType": {
"show": true,
"type": [
"line",
"bar",
"stack",
"tiled"
],
"title": {
"line": "\u5207\u6362\u4e3a\u6298\u7ebf\u56fe",
"bar": "\u5207\u6362\u4e3a\u67f1\u72b6\u56fe",
"stack": "\u5207\u6362\u4e3a\u5806\u53e0",
"tiled": "\u5207\u6362\u4e3a\u5e73\u94fa"
},
"icon": {}
}
}
}
};
chart_230081edc72b4d1bb7f50f04c025a37b.setOption(option_230081edc72b4d1bb7f50f04c025a37b);
</script>
</body>
</html>

@ -0,0 +1,43 @@
import pyecharts
from pyecharts.charts import Line
from pyecharts import options as opts
import pandas as pd
from getData import getData
def line():
getData()
# 读取数据
data = pd.read_csv('北京市区房价.csv', encoding='utf-8')
datas = data['行政区']
compare_month = data['环比上月']
compare_year = data['同比上年']
# 移除百分号并转换为浮点数
mothon_list_float = [float(x.strip('%'))for x in compare_month] # 转换为小数百分比转为0-1之间
year_list_float = [float(x.strip('%'))for x in compare_year] # 转换为小数百分比转为0-1之间
# 转换为列表
name_list = datas.tolist()
# 打印转换后的列表以验证
print(mothon_list_float)
# 创建Line对象并设置数据
line = Line(
init_opts=opts.InitOpts(width='1000px',height='500px',page_title="多折线")
)
line.add_xaxis(xaxis_data=name_list) # x轴
line.add_yaxis(series_name='环比上月', y_axis=mothon_list_float) # 使用转换后的数据
line.add_yaxis(series_name='同比上年', y_axis=year_list_float) # 使用转换后的数据
line.set_global_opts(
title_opts=opts.TitleOpts(
title="北京市区房价趋势图"
),
toolbox_opts=opts.ToolboxOpts(
is_show=True
)
)
# 渲染图表到HTML文件
line.render('line.html')

@ -0,0 +1,45 @@
from tkinter import *
import Home
user_login={'aaa':'123456','bbb':'888888','ccc':'333333'}
count=0
def login():
global count
username=entry_username.get()
if username not in user_login:
lable_message.config(text="账号错误!")
else:
password=entry_password.get()
if(password==user_login[username]):
lable_message.config(text="登陆成功!")
window.destroy()
h=Home.Home()
else:
lable_message.config(text="你还可以尝试{}".format(2-count))
count+=1
if count==3:
lable_message.config(text="登陆失败!")
btn_login.config(state='disabled')
window = Tk()
window.title('用户登陆')
window.geometry("300x200")
lable_usename=Label(window,text="账号:")
lable_usename.pack()
entry_username=Entry(window)
entry_username.pack()
lable_password=Label(window,text="密码")
lable_password.pack()
entry_password=Entry(window)
entry_password.pack()
#按钮登陆绑定login函数
btn_login=Button(window,text="登陆",command=login)
btn_login.pack()
lable_message=Label(window,text="")
lable_message.pack()
window.mainloop()

@ -0,0 +1,219 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>地图</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/maps/beijing.js"></script>
</head>
<body >
<div id="c7ffa23106124fae8285c749fb373293" class="chart-container" style="width:900px; height:500px; "></div>
<script>
var chart_c7ffa23106124fae8285c749fb373293 = echarts.init(
document.getElementById('c7ffa23106124fae8285c749fb373293'), 'white', {renderer: 'canvas'});
var option_c7ffa23106124fae8285c749fb373293 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"aria": {
"enabled": false
},
"color": [
"#5470c6",
"#91cc75",
"#fac858",
"#ee6666",
"#73c0de",
"#3ba272",
"#fc8452",
"#9a60b4",
"#ea7ccc"
],
"series": [
{
"type": "map",
"name": "\u5e73\u5747\u623f\u4ef7",
"label": {
"show": true,
"margin": 8
},
"map": "\u5317\u4eac",
"data": [
{
"name": "\u660c\u5e73\u533a",
"value": 44538
},
{
"name": "\u671d\u9633\u533a",
"value": 72344
},
{
"name": "\u5927\u5174\u533a",
"value": 44350
},
{
"name": "\u4e1c\u57ce\u533a",
"value": 111850
},
{
"name": "\u623f\u5c71\u533a",
"value": 28210
},
{
"name": "\u4e30\u53f0\u533a",
"value": 61021
},
{
"name": "\u6d77\u6dc0\u533a",
"value": 102057
},
{
"name": "\u6000\u67d4\u533a",
"value": 28193
},
{
"name": "\u95e8\u5934\u6c9f\u533a",
"value": 38216
},
{
"name": "\u5bc6\u4e91\u533a",
"value": 21182
},
{
"name": "\u5e73\u8c37\u533a",
"value": 22198
},
{
"name": "\u77f3\u666f\u5c71\u533a",
"value": 54453
},
{
"name": "\u987a\u4e49\u533a",
"value": 36628
},
{
"name": "\u901a\u5dde\u533a",
"value": 41657
},
{
"name": "\u897f\u57ce\u533a",
"value": 128073
},
{
"name": "\u5ef6\u5e86\u533a",
"value": 19673
}
],
"roam": true,
"aspectScale": 0.75,
"nameProperty": "name",
"selectedMode": false,
"zoom": 1,
"zlevel": 0,
"z": 2,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"mapValueCalculation": "sum",
"showLegendSymbol": true,
"emphasis": {}
}
],
"legend": [
{
"data": [
"\u5e73\u5747\u623f\u4ef7"
],
"selected": {},
"show": true,
"left": "left",
"orient": "vertical",
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14,
"backgroundColor": "transparent",
"borderColor": "#ccc",
"borderRadius": 0,
"pageButtonItemGap": 5,
"pageButtonPosition": "end",
"pageFormatter": "{current}/{total}",
"pageIconColor": "#2f4554",
"pageIconInactiveColor": "#aaa",
"pageIconSize": 15,
"animationDurationUpdate": 800,
"selector": false,
"selectorPosition": "auto",
"selectorItemGap": 7,
"selectorButtonGap": 10
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"enterable": false,
"confine": false,
"appendToBody": false,
"transitionDuration": 0.4,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5,
"order": "seriesAsc"
},
"title": [
{
"show": true,
"text": "\u5317\u4eac\u5e02\u5e02\u533a",
"target": "blank",
"subtarget": "blank",
"left": "center",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
],
"visualMap": {
"show": true,
"type": "continuous",
"min": 19000,
"max": 130000,
"inRange": {
"color": [
"#1E9600",
"#fff200",
"#ff0000"
]
},
"calculable": true,
"inverse": false,
"splitNumber": 5,
"hoverLink": true,
"orient": "vertical",
"padding": 5,
"showLabel": true,
"itemWidth": 20,
"itemHeight": 140,
"borderWidth": 0
}
};
chart_c7ffa23106124fae8285c749fb373293.setOption(option_c7ffa23106124fae8285c749fb373293);
</script>
</body>
</html>

@ -0,0 +1,43 @@
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')
Loading…
Cancel
Save