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.
|
|
|
|
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')
|
|
|
|
|
|