您的当前位置:首页正文

小白学Python(13)——pyecharts绘制柱状图条形图Bar

2024-02-20 来源:好走旅游网
⼩⽩学Python(13)——pyecharts绘制柱状图条形图Bar

Bar-基本⽰例

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.choose())

8 .add_yaxis(\"商家A\", Faker.values()) 9 .add_yaxis(\"商家B\", Faker.values())

10 .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-基本⽰例\", subtitle=\"我是副标题\"))11 )12

13 bar.render()

翻转 XY 轴

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.choose())

8 .add_yaxis(\"商家A\", Faker.values()) 9 .add_yaxis(\"商家B\", Faker.values())10 .reversal_axis()

11 .set_series_opts(label_opts=opts.LabelOpts(position=\"right\"))

12 .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-翻转 XY 轴\"))13 )14

15 bar.render()

Bar-堆叠数据(全部)

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.choose())

8 .add_yaxis(\"商家A\", Faker.values(), stack=\"stack1\") 9 .add_yaxis(\"商家B\", Faker.values(), stack=\"stack1\")

10 .set_series_opts(label_opts=opts.LabelOpts(is_show=False))

11 .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-堆叠数据(全部)\"))12 )13

14 bar.render()

Bar-MarkPoint(指定类型)

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.choose())

8 .add_yaxis(\"商家A\", Faker.values()) 9 .add_yaxis(\"商家B\", Faker.values())

10 .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-MarkPoint(指定类型)\"))11 .set_series_opts(

12 label_opts=opts.LabelOpts(is_show=False),13 markpoint_opts=opts.MarkPointOpts(14 data=[

15 opts.MarkPointItem(type_=\"max\", name=\"最⼤值\"),16 opts.MarkPointItem(type_=\"min\", name=\"最⼩值\"),17 opts.MarkPointItem(type_=\"average\", name=\"平均值\"),18 ]19 ),20 )21 )22

23 bar.render()

Bar-DataZoom(slider-⽔平)

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.days_attrs)

8 .add_yaxis(\"商家A\", Faker.days_values) 9 .set_global_opts(

10 title_opts=opts.TitleOpts(title=\"Bar-DataZoom(slider-⽔平)\"),11 datazoom_opts=opts.DataZoomOpts(),12 )13 )14

15 bar.render()

Bar-DataZoom(slider-垂直)

1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Bar 4

5 bar=( 6 Bar()

7 .add_xaxis(Faker.days_attrs)

8 .add_yaxis(\"商家A\", Faker.days_values, color=Faker.rand_color())

9 .set_global_opts(

10 title_opts=opts.TitleOpts(title=\"Bar-DataZoom(slider-垂直)\"),11 datazoom_opts=opts.DataZoomOpts(orient=\"vertical\"),12 )13 )14

15 bar.render()

因篇幅问题不能全部显示,请点此查看更多更全内容