日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

可视化 | pyecharts之柱状图常用配置篇

發布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 可视化 | pyecharts之柱状图常用配置篇 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

pyecharts的可視化大法,讓人愛不釋手。柱狀圖是我們最為常用的可視化統計圖,本篇主要介紹了pyecharts的繪制柱狀圖的常用配置,主要包括以下內容:

  • 基礎柱狀圖
  • 隱藏圖例標簽數字
  • 坐標軸名稱命名
  • 旋轉X軸標簽
  • 增加標記線或者標記點
  • 柱子寬度設置
  • 不同系列間柱間距離
  • 自定義柱狀顏色
  • 柱狀堆疊圖
  • 在柱狀圖中同時繪制折線圖
  • 實例詳解

    基礎柱狀圖

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")))bar.render_notebook()

    隱藏圖例標簽數字

    在系列配置項中set_series_opts()的標簽設置

    label_opts=opts.LabelOpts(is_show=False),False為隱藏數字

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)))bar.render_notebook()

    坐標軸名稱命名

    全局配置項中,yaxis_opts=opts.AxisOpts(name)以及xaxis_opts=opts.AxisOpts(name)參數設置

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, stack = "stack1") # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="坐標軸命名"),yaxis_opts=opts.AxisOpts(name="課程成績"),xaxis_opts=opts.AxisOpts(name="課程類別")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)) )bar.render_notebook()

    旋轉x軸標簽

    全局配置項中,xaxis_opts=opts.AxisOpts(totate)參數設置,rotate = -15,垂直x軸標簽逆時針旋轉15度

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["很長很長的高微","很長很長的高管","很長很長的高計","很長很長的會計","很長很長的金融","很長很長的計算機"] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),title_opts=opts.TitleOpts(title="旋轉x軸標簽", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)) )bar.render_notebook()

    旋轉坐標軸

    系列配置項中,reversal_axis(),label_opts=opts.LabelOpts(position=“right”)

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, stack = "stack1") # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.reversal_axis().set_global_opts(title_opts=opts.TitleOpts(title="旋轉坐標軸")).set_series_opts(label_opts=opts.LabelOpts(is_show=False,position="right")) )bar.render_notebook()

    增加標記線或者標記點

    一、指定值的標記線

    在系列配置項中set_series_opts()的markline_opts=opts.MarkLineOpts()

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="增加標記線", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False),markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=75, name="yAxis=75")])) # 75分合格線)bar.render_notebook()

    二、平均值、最小值、最大值的標記線

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置#.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False),markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="min", name="最小值"),opts.MarkLineItem(type_="max", name="最大值"),opts.MarkLineItem(type_="average", name="平均值")])))bar.render_notebook()

    三、增加標記點

    從“線型”替換成“點型”,markline_opts參數設置變為markpoint_opts

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1) # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False),markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min", name="最小值"),opts.MarkPointItem(type_="max", name="最大值"),opts.MarkPointItem(type_="average", name="平均值")])))bar.render_notebook()

    柱子寬度設置

    .add_yaxis(category_gap=“80%”)參數設置,值越大表明柱子間的間距越大,柱子寬度越小

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, category_gap="50%") # y軸設置.add_yaxis("學生B", y_value2, category_gap="50%") # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="柱子寬度設置", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)) )bar.render_notebook()

    不同系列柱間距離

    .add_yaxis(gap=“0%”)參數設置,,值越小表明不同系列之間的柱間距離越小

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, gap="0%") # y軸設置.add_yaxis("學生B", y_value2, gap="0%") # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False),markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=75, name="yAxis=75")])) # 75分合格線)bar.render_notebook()

    自定義柱狀顏色

    .add_yaxis()參數設置,itemstyle_opts=opts.ItemStyleOpts(color)

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, itemstyle_opts=opts.ItemStyleOpts(color="gray")) # y軸設置.add_yaxis("學生B", y_value2, itemstyle_opts=opts.ItemStyleOpts(color="black")) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)))bar.render_notebook()

    柱狀堆疊

    .add_yaxis()參數設置,stack參數設置

    from pyecharts import options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] y_value1plus = [10, 10, 10, 10, 10, 10] #學生1三好學生每門課程加10分 y_value2 = [95, 88, 85, 96, 87, 76]bar = (Bar().add_xaxis(x_index).add_yaxis("學生A", y_value1, stack = "stack1") # y軸設置.add_yaxis("加分", y_value1plus, stack = "stack1") # y軸設置.add_yaxis("學生B", y_value2) # y軸設置.set_global_opts(title_opts=opts.TitleOpts(title="柱狀堆疊", subtitle="我是副標題")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)) )bar.render_notebook()

    在柱狀圖中同時繪制折線圖

    import pyecharts.options as opts from pyecharts.charts import *x_index = ["高微","高管","高計","會計","金融","計算機"] y_value1 = [85, 90, 95, 75, 92, 98] classrank = [30, 25, 10, 60, 15, 5]bar = (Bar(init_opts=opts.InitOpts(width="800px", height="400px")).add_xaxis(xaxis_data=x_index).add_yaxis(series_name="課程成績",y_axis=y_value1,category_gap="50%",label_opts=opts.LabelOpts(is_show=False)).extend_axis( # 第二坐標軸yaxis=opts.AxisOpts(name="課程排名",type_="value",min_=0,max_=100,interval=20,axislabel_opts=opts.LabelOpts(formatter="{value} %") # 設置坐標軸格式)).set_global_opts(tooltip_opts=opts.TooltipOpts(is_show=True, trigger="axis", axis_pointer_type="cross"),xaxis_opts=opts.AxisOpts(type_="category",axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),),yaxis_opts=opts.AxisOpts(name="課程成績",type_="value",min_=0,max_=100,interval=20,axislabel_opts=opts.LabelOpts(formatter="{value} 分"), # 設置坐標軸格式axistick_opts=opts.AxisTickOpts(is_show=True),splitline_opts=opts.SplitLineOpts(is_show=True),),) )line = (Line().add_xaxis(xaxis_data=x_index).add_yaxis(series_name="課程成績",yaxis_index=1,y_axis=classrank,itemstyle_opts=opts.ItemStyleOpts(color="blue"),label_opts=opts.LabelOpts(is_show=False),z=2 # 使折線圖顯示在柱狀圖上面) )bar.overlap(line).render_notebook()

    參考資料

    [1]https://gallery.pyecharts.org/#/Bar/README

    總結

    以上是生活随笔為你收集整理的可视化 | pyecharts之柱状图常用配置篇的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。