day13绘图

  1. 折线图

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')
  1. 地图

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')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值