可视化 |
您所在的位置:网站首页 › 柱形图怎么修改文字 › 可视化 |
前言 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()全局配置项中,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()[1]https://gallery.pyecharts.org/#/Bar/README |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |