Python:构建基础柱状图,时间柱状图(笔记)

Part1:(基础柱状图) :

# 演示基础柱状图
from pyecharts.charts import Bar
# 导入改变数值位置的函数
from pyecharts.options import LabelOpts

# 使用Bar构建基础柱状图
bar = Bar()
# 添加x轴数据
bar.add_xaxis((["中国","美国","英国"]))
# 添加y轴数据
bar.add_yaxis("GDP",[30,20,10],label_opts=LabelOpts(position="right"))
# 反转x,y轴
bar.reversal_axis()
# 构图
bar.render("基础柱状图.html")

 

Part2:(基础时间轴柱状图): 

# 演示带有时间线的柱状图开发

from pyecharts.charts import Bar, Timeline
from pyecharts.options import LabelOpts
from pyecharts.globals import ThemeType
bar1 = Bar()
# x坐标
bar1.add_xaxis(["中国","美国","英国"])
# y坐标
bar1.add_yaxis("GDP",[30,20,10],label_opts=LabelOpts(position="right"))
# 反转坐标轴
bar1.reversal_axis()

bar2 = Bar()
# x坐标
bar2.add_xaxis(["中国","美国","英国"])
# y坐标
bar2.add_yaxis("GDP",[40,60,50],label_opts=LabelOpts(position="right"))
# 反转坐标轴
bar2.reversal_axis()

bar3 = Bar()
# x坐标
bar3.add_xaxis(["中国","美国","英国"])
# y坐标
bar3.add_yaxis("GDP",[60,90,70],label_opts=LabelOpts(position="right"))
# 反转坐标轴
bar3.reversal_axis()

# 构建时间线对象
timeline = Timeline(
    {"theme": ThemeType.LIGHT}
)
# 在时间线内添加柱状图对象
timeline.add(bar1,"point 1")
timeline.add(bar2,"point 2")
timeline.add(bar3,"point 3")

# 自动播放设置
timeline.add_schema(
    play_interval=1000,
    # 播放间隔
    is_timeline_show=True,
    # 是否展示时间线
    is_auto_play=True,
    # 是否自动播放
    is_loop_play=True
    #是否循环播放


)

# 主题设置
# 在创建时间线对象时传入“theme”:
# timeline = Timeline(
#     {"theme": ThemeType.LIGHT}
# )
# 创建图像
timeline.render("基础时间线柱状图.html")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要调整柱状图的边线粗细,你可以使用matplotlib库中的plot函数的linewidth参数。例如,你可以使用以下代码来绘制柱状图并调整边线的粗细: ``` import matplotlib.pyplot as plt # 基础数据 S = [21, 23, 12, 35, 36, 33, 30] fig, ax = plt.subplots() # 绘制柱状图,并设置边线粗细为3 ax.bar(range(len(S)), S, linewidth=3) # 设置图表的标题 ax.set_title('温度', fontsize=24) # 设置x轴的标签 ax.set_xlabel('星期', fontsize=14) # 设置y轴的标签 ax.set_ylabel('温度', fontsize=13) plt.show() ``` 在这个例子中,我们使用了`bar`函数来绘制柱状图,并通过`linewidth`参数设置了边线的粗细为3。你可以根据需要调整这个值来达到想要的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Python绘图笔记](https://blog.csdn.net/Accepted__/article/details/125412667)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [修改matplotlib绘制出图表 基本属性(一)](https://blog.csdn.net/weixin_43270539/article/details/126741033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值