Skip to content
python
"""  
柱状图  
"""  
from pyecharts.options import *  
from pyecharts.charts import Bar, Timeline  
from pyecharts.globals import ThemeType  
  
# 使用bar构建基础柱状图  
bar1 = Bar()  
# 添加x轴  
bar1.add_xaxis(["中国", "美国", "英国"])  
# 添加y轴  
bar1.add_yaxis("GDP", [30, 50, 10], label_opts=LabelOpts(position="right"))  
#翻转x轴和y轴  
bar1.reversal_axis()  
  
bar2 = Bar()  
bar2.add_xaxis(["中国", "美国", "英国"])  
bar2.add_yaxis("GDP", [50, 55, 15], label_opts=LabelOpts(position="right"))  
bar2.reversal_axis()  
  
bar3 = Bar()  
bar3.add_xaxis(["中国", "美国", "英国"])  
bar3.add_yaxis("GDP", [70, 60, 40], label_opts=LabelOpts(position="right"))  
bar3.reversal_axis()  
  
  
# 构建时间线对象  
timeline = Timeline({"theme": ThemeType.LIGHT}) # 主题设置  
  
# 在时间线内添加柱状图对象  
timeline.add(bar1, "点1")  
timeline.add(bar2, "点2")  
timeline.add(bar3, "点3")  
  
# 自动播放设置  
timeline.add_schema(  
play_interval=1000, # 自动播放时间间隔  
is_timeline_show=True,  
is_auto_play=True,  
is_loop_play=True  
)  
  
# 设置右侧数值标签  
  
# 绘图  
timeline.render("基础时间线柱状图.html")

评论区

欢迎留言、补充或勘误。

xiaoba.blog