PYTHON基础综合案例(数据可视化)

PYTHON基础综合案例(数据可视化)

pyecharts

入门操作

  • pyecharts模块中有很多的配置选项,常用到2个类别的选项:

    • 全局配置选项
      • 可以通过set_global_opts方法来进行配置
        • TitleOpts 标题配置项
        • LegendOpts 图列配置项
        • ToolboxOpts 工具箱配置项
        • VisualMapOpts 视觉映射配置项
        • TooltipOpts 提示框配置项
        • DataZoomOpts 区域缩放配置项
    • 系列配置选项
  • 基础折线图

import pyecharts

# 得到折线图对象
line = pyecharts.charts.Line()
# 添加X轴数据
line.add_xaxis(["A国","B国","C国"])
# 添加Y轴数据
line.add_yaxis("GDP",[15,25,22])
# 生成图表
line.render()
  • 基础地图
# 国内疫情地图

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

a = open("E:/DOWNLOADS/资料/资料/可视化案例数据/地图数据/疫情.txt","r",encoding="UTF-8")
b = a.read()
c = json.loads(b)['areaTree'][0]['children']
data = []
for x in c:
    tuple_data =(x['name'],x['total']['confirm']) #需要根据/省,市,自治区加后缀匹配名称
    data.append(tuple_data)
map = Map()

map.add("国内疫情地图",data,"china")
map.set_global_opts(
    visualmap_opts=VisualMapOpts()
)
map.render("china_data.html")
a.close()
  • 基础柱状图
# 基础柱状图

from pyecharts.charts import Bar

bar = Bar()
bar.add_xaxis(["A国","B国","C国"])
bar.add_yaxis("GDP",[45,60,30])
# 反转XY轴
bar.reversal_axis()
bar.render("ZhuZhuangTu.html")
posted @ 2023-02-28 15:16  Learn1ng  阅读(118)  评论(0)    收藏  举报