折线图
from pyecharts.charts import Line
from pyecharts import options
import xlrd
# 打开表格
wb = xlrd.open_workbook('E:\\数据\\分省年度数据.xls')
sheet1 = wb.sheet_by_index(0)
# 读取数据
m_c = sheet1.ncols
data = []
time = []
for i in range(m_c-1, 0, -1):
data.append(sheet1.cell(1, i).value)
time.append(sheet1.cell(0, i).value)
# data = sheet1.row_value(1, 1, m_c+1)
# 制作折线图
line = Line()
line.add_xaxis(time)
line.add_yaxis('北京生产总值', data)
line.set_global_opts(
title_opts=options.TitleOpts(
title='北京发展状况'
),
legend_opts=options.LegendOpts(
is_show=True
),
xaxis_opts=options.AxisOpts(
name='时间'
),
yaxis_opts=options.AxisOpts(
name='生产总值'
),
datazoom_opts=options.DataZoomOpts(
is_show=True
)
)
line.set_series_opts(
label_opts=options.LabelOpts(
is_show=True
)
)
# 渲染图表
line.render('files/折线图.html')
地图
from pyecharts.charts import Map
from pyecharts import options
import xlrd
# 打开表格
wb = xlrd.open_workbook('E:\\数据\\分省年度数据.xls')
sheet1 = wb.sheet_by_index(0)
# 读取数据
m_r = sheet1.nrows
data = []
map1 = Map()
for i in range(m_r-1, 0, -1):
data.append((sheet1.cell(i, 0).value, sheet1.cell(i, 1).value))
map1.add(
'生产总值',
data
)
map1.set_global_opts(
visualmap_opts=options.VisualMapOpts(
is_show=True,
# min_=0,
# max_=150000,
is_piecewise=True,
pieces=[
{'min': 0, 'max': 9999},
{'min': 10000, 'max': 14999},
{'min': 15000, 'max': 29999},
{'min': 30000, 'max': 59999},
{'min': 60000, 'max': 99999},
{'min': 100000, 'max': 150000}
]
),
legend_opts=options.LegendOpts(
is_show=True
),
title_opts=options.TitleOpts(
title='各省生产总值'
)
)
map1.render('files/地图.html')