python 简单图代码【折线图,地图,柱状图】

一,折线图
 

from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
# 导入相关全局配置包
line = Line()
line.add_xaxis(['中国', '美国', '英国', '日本'])
line.add_yaxis('GDP', [88, 50, 47, 62])
line.set_global_opts(
    title_opts=TitleOpts(title='GDP展示', pos_left='center',pos_bottom='1%'),
#  标题设置,标题的左右位置,标题距离底部的距离
    legend_opts=LegendOpts(is_show=True),
# 图例是否显示
    toolbox_opts=ToolboxOpts(is_show=True),
# 工具箱
    visualmap_opts=VisualMapOpts(max_=20)
# 视觉映射
)
line.render()
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
line = Line()
line.add_xaxis(['中国', '美国', '英国', '日本'])
line.add_yaxis('GDP', [88, 50, 47, 62])
line.set_global_opts(
    title_opts=TitleOpts(title='GDP展示', pos_left='center',pos_bottom='1%'),
    legend_opts=LegendOpts(is_show=True),
    toolbox_opts=ToolboxOpts(is_show=True),
    visualmap_opts=VisualMapOpts(max_=20)
)
line.render()

二,地图

from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts

map = Map()
data = [
    ('北京市', 100),
    ('上海市', 85),
    ('杭州市', 99),
    ('浙江省', 95),
    ('天津市', 83),
    ('重庆市', 79)
]
map.add('地图', data, 'china')
# 注意小写
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
# 可以显示颜色
        is_calculable=True
    )
)
map.render()

# 在ab173.com可以查找对应颜色标号

from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts

map = Map()
data = [
    ('北京市', 100),
    ('上海市', 85),
    ('杭州市', 99),
    ('浙江省', 95),
    ('天津市', 83),
    ('重庆市', 79)
]
map.add('地图', data, 'china')
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_calculable=True
    )
)
map.render()

三,柱状图

# 动态柱状图
from pyecharts.charts import Bar, Timeline
from pyecharts.options import *
from pyecharts.globals import ThemeType

bar1 = Bar()
bar1.add_xaxis(['中国', '美国', '英国'])
bar1.add_yaxis('GDP', [50, 20, 10], label_opts=LabelOpts(position='right'))
bar1.reversal_axis()

bar2 = Bar()
bar2.add_xaxis(['中国', '美国', '英国'])
bar2.add_yaxis('GDP', [60, 30, 20], label_opts=LabelOpts(position='right'))
bar2.reversal_axis()

bar3 = Bar()
bar3.add_xaxis(['中国', '美国', '英国'])
bar3.add_yaxis('GDP', [100, 60, 70], label_opts=LabelOpts(position='right'))
bar3.reversal_axis()

bar4 = Bar()
bar4.add_xaxis(['中国', '美国', '英国'])
bar4.add_yaxis('GDP', [70, 50, 40], label_opts=LabelOpts(position='right'))
bar4.reversal_axis()

timeline = Timeline()
timeline.add(bar1, '2021年GDP')
timeline.add(bar2, '2023年GDP')
timeline.add(bar3, '2025年GDP')
timeline.add(bar4, '2027年GDP')
# 设置自动播放
timeline.add_schema(
    play_interval=1000,
    is_timeline_show=True,
    is_auto_play=True,
    is_loop_play=True
)
timeline.render('基础柱状图-时间线.html')
from pyecharts.charts import Bar, Timeline
from pyecharts.options import *
from pyecharts.globals import ThemeType

bar1 = Bar()
bar1.add_xaxis(['中国', '美国', '英国'])
bar1.add_yaxis('GDP', [50, 20, 10], label_opts=LabelOpts(position='right'))
bar1.reversal_axis()

bar2 = Bar()
bar2.add_xaxis(['中国', '美国', '英国'])
bar2.add_yaxis('GDP', [60, 30, 20], label_opts=LabelOpts(position='right'))
bar2.reversal_axis()

bar3 = Bar()
bar3.add_xaxis(['中国', '美国', '英国'])
bar3.add_yaxis('GDP', [100, 60, 70], label_opts=LabelOpts(position='right'))
bar3.reversal_axis()

bar4 = Bar()
bar4.add_xaxis(['中国', '美国', '英国'])
bar4.add_yaxis('GDP', [70, 50, 40], label_opts=LabelOpts(position='right'))
bar4.reversal_axis()

timeline = Timeline()
timeline.add(bar1, '2021年GDP')
timeline.add(bar2, '2023年GDP')
timeline.add(bar3, '2025年GDP')
timeline.add(bar4, '2027年GDP')

timeline.add_schema(
    play_interval=1000,
    is_timeline_show=True,
    is_auto_play=True,
    is_loop_play=True
)
timeline.render('基础柱状图-时间线.html')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值