数据可视化之【pycharts】

# 【matplotlib绘图思路】
# 0. 准备数据(数据爬取-数据清洗-数据结构化): 数据格式要符合传参的需求
# 1. 创建一个画布实例
# 2. 基于这个画布实例,划分区域,并在对应区域创建坐标系实例(直角坐标系实例,极坐标系实例)
# 3. 通过坐标系实例,调用所需的绘图方法,实现绘图
# 4. 图表辅助元素的定制和样式美化(花时间最多,客户需求经常改变,要随之调整)
# 5. 展示图表(渲染图表)


# 【pyecharts绘图思路】
# 0.导入需要用到的图表类(Bar,Line,Scatter,Pie)
# 1. 准备数据(数据爬取-数据清洗-数据结构化): 数据格式要符合传参的需求
# 2.通过导入的图表类,创建图表实例
# 3.往图表实例填充数据,即完成绘图
# 4.设置“系列配置项”和“全局配置项”--> 可做可不做(类似于matplotlib的:图表辅助元素的定制和样式美化)
# 5. 展示图表(渲染图表)


# 【pyecharts的常用的图表分成两大类】
# 1. 带x轴和y轴的直角坐标系图表(柱形图,折线图,散点图,箱型图)
#     .add_xaxis()
#     .add_yaxis()
    
# 2. 不带x轴和y轴的基本图表(饼图,环图,词云图,桑基图,漏斗图, 雷达图)
#     .add()
    
    
    

 

# 【pyecharts绘图思路】
# 0.导入需要用到的图表类(Bar,Line,Scatter,Pie)
from pyecharts.charts import Bar, Line, Scatter, Pie
import pyecharts.options as opts

# 1. 准备数据(数据爬取-数据清洗-数据结构化): 数据格式要符合传参的需求
bar_x =      ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
bar_height1 = [5,       20,       36,       10,     75,        90]
bar_height2 = [15,       25,       33,       11,     75,        90]

# 2.通过导入的图表类,创建图表实例

bar = Bar() # 柱形图实例


# 3.往图表实例填充数据,即完成绘图
bar.add_xaxis(     bar_x     )

bar.add_yaxis("商家A", bar_height1 )
bar.add_yaxis("商家B", bar_height2 )

# 4.设置“系列配置项”和“全局配置项”--> 可做可不做(类似于matplotlib的:图表辅助元素的定制和样式美化)
# 全局配置项中,“图例”和“提示框”是默认打开的。
# 系列配置项中,有些参数在set_global_opts设置中会生效,而有些参数却在set_series_opts设置中生效:
# 设置“全局配置项”(设置图表外部元素的样式)
bar.set_global_opts(
                    title_opts=opts.TitleOpts(title="这是我的第一个pyechars柱形图", subtitle="数据可视化"), # 标题
                    legend_opts=opts.LegendOpts(),  # 图例
                    tooltip_opts=opts.TooltipOpts( border_width= 2, border_color='red'), # 提示框
                    toolbox_opts=opts.ToolboxOpts(pos_left = '70%', pos_top='80' ),  # 工具箱
                    datazoom_opts=opts.DataZoomOpts(),  # 区域缩放条
                    visualmap_opts=opts.VisualMapOpts(),  # 视觉映射条(用来通过颜色筛选展示)
    
                    # 通过“轴配置项”,配置x轴
                    xaxis_opts=opts.AxisOpts(name='我是X轴', name_rotate=60, name_gap=45,
                                              axislabel_opts=opts.LabelOpts(color='red',
                                                                           font_size=10,
                                                                           font_style='italic',
                                                                           margin=20, # 轴标签与轴脊的距离
                                                                           )
                                            ), 
    
                    # 通过“轴配置项”,配置y轴
                    yaxis_opts=opts.AxisOpts(name='我是Y轴',  # 轴的名称
                                             min_  =0, max_ = 200, # 刻度范围
                                             interval = 20,  # 配合min_和max_参数,调整刻度位置
                                             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True, length=40),
                                             axislabel_opts=opts.LabelOpts(color='red',
                                                                           font_size=10,
                                                                           font_style='italic',)

                                            ),  # 
                   )

# 设置“系列配置项”(设置图表内部元素的样式)
bar.set_series_opts(
                    label_opts=opts.LabelOpts(color='green',
                                              font_size=20,
                                              font_style='italic',
                                              position ='top',
                                              distance = 30,
                                              )
                   
                   
                   )


# 5. 展示图表(渲染图表)
bar.render_notebook()  # 渲染到jupyter notebook编辑器页面


# 【pyecharts绘图思路】
# 0.导入需要用到的图表类(Bar,Line,Scatter,Pie)
from pyecharts.charts import Bar, Line, Scatter, Pie
import pyecharts.options as opts

# 1. 准备数据(数据爬取-数据清洗-数据结构化): 数据格式要符合传参的需求
x =      ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
y1 = [5,       20,       36,       10,     75,        90]
y2 = [15,       25,       33,       11,     33,        45]

# 2.通过导入的图表类,创建图表实例

line = Line() # 柱形图实例


# 3.往图表实例填充数据,即完成绘图
line.add_xaxis(     x     )

line.add_yaxis("商家A", y1 )
line.add_yaxis("商家B", y2 )

# 4.设置“系列配置项”和“全局配置项”--> 可做可不做(类似于matplotlib的:图表辅助元素的定制和样式美化)
# 全局配置项中,“图例”和“提示框”是默认打开的。
# 系列配置项中,有些参数在set_global_opts设置中会生效,而有些参数却在set_series_opts设置中生效:
# 设置“全局配置项”(设置图表外部元素的样式)
line.set_global_opts(
                    title_opts=opts.TitleOpts(title="这是我的第一个pyechars折线图", subtitle="我感觉超级简单嘛"), # 标题
                    legend_opts=opts.LegendOpts(),  # 图例
                    tooltip_opts=opts.TooltipOpts( border_width= 2, border_color='red'), # 提示框
                    toolbox_opts=opts.ToolboxOpts(pos_left = '10%', pos_top='20%' ),  # 工具箱
                    datazoom_opts=opts.DataZoomOpts(),  # 区域缩放条
                    visualmap_opts=opts.VisualMapOpts(),  # 视觉映射条(用来通过颜色筛选展示)
    
                    # 通过“轴配置项”,配置x轴
                    xaxis_opts=opts.AxisOpts(name='我是X轴', name_rotate=60, name_gap=45,
                                              axislabel_opts=opts.LabelOpts(color='red',
                                                                           font_size=10,
                                                                           font_style='italic',
                                                                           margin=20, # 轴标签与轴脊的距离
                                                                           )
                                            ), 
    
                    # 通过“轴配置项”,配置y轴
                    yaxis_opts=opts.AxisOpts(name='我是Y轴',  # 轴的名称
                                             min_  =0, max_ = 200, # 刻度范围
                                             interval = 20,  # 配合min_和max_参数,调整刻度位置
                                             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True, length=40),
                                             axislabel_opts=opts.LabelOpts(color='red',
                                                                           font_size=10,
                                                                           font_style='italic',)

                                            ),  # 
    

                   )

# # 设置“系列配置项”(设置图表内部元素的样式)
line.set_series_opts(
                    label_opts=opts.LabelOpts(color='orange',
                                              font_size=20,
                                              font_style='italic',
                                              position ='top',
                                              distance = 30,
                                              ),    
    
#                     linestyle_opts=opts.LineStyleOpts(type_ = 'dashed', # 线型
#                                                       color = 'red'   # 线的颜色
#                                                      ), 
    
#                    markpoint_opts=opts.MarkPointOpts(symbol = 'triangle', # 数据标记点类型
#                                                       symbol_size = 40,
#                                                      )  
    
                   )


# 5. 展示图表(渲染图表)
line.render_notebook()  # 渲染到jupyter notebook编辑器页面

[76]



# 0.导入需要用到的图表类(Bar,Line,Scatter,Pie)
from pyecharts.charts import Bar, Line, Scatter, Pie
import pyecharts.options as opts


x =      ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
y1 = [5,       20,       36,       10,     75,        90]
y2 = [15,       25,       33,       11,     33,        45]

# 2.通过导入的图表类,创建图表实例

c = (

Scatter()
    .add_xaxis(x)
    .add_yaxis("商家A", y1 )
    .add_yaxis("商家B", y2 )
    .set_global_opts()
    .set_series_opts()

)

c.render_notebook()  

 

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值