为了账号安全,请及时绑定邮箱和手机立即绑定

如何在多个子图上设置相同的轴值?

如何在多个子图上设置相同的轴值?

慕村9548890 2022-07-05 17:53:36
我有 x 和 y 的数据我想创建每条线的小型多折线图。我尝试了此页面中的代码。我修改了几行以匹配我的代码。这是我的代码:fig, axs = plt.subplots(4, 5, figsize = (15,15))ylim = (-100, 55)k = 0for i in range(4):    for j in range(5):        to_plot = real.loc[real['order_number'] == orderlist[k]]        axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])        axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])        k+=1这orderlist是一个包含订单号的列表。我想让每个图表对 y 轴具有相同的限制,但ylim = (-100,55)不做这项工作,而是让这张图表具有不同的 y 轴。
查看完整描述

1 回答

?
大话西游666

TA贡献1817条经验 获得超14个赞

ylim = (-100, 55)

它自己什么都不做,只是创建一个tuple被调用的ylim. 您需要做的是使用作为参数调用matplotlib.axes.Axes.set_ylim每个axes实例的方法,即ylim


fig, axs = plt.subplots(4, 5, figsize = (15,15))

ylim = (-100, 55)

k = 0

for i in range(4):

    for j in range(5):

        to_plot = real.loc[real['order_number'] == orderlist[k]]

        axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])

        axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])

        axs[i,j].set_ylim(ylim)

        k+=1

如果您不希望绘制绘图之间的 y 刻度标签(因为所有绘图的 y 轴都相同),您也可以这样做


fig, axs = plt.subplots(4, 5, sharey=True, figsize = (15,15))

axs[0,0].set_ylim([-100, 55])

k = 0

for i in range(4):

    for j in range(5):

        to_plot = real.loc[real['order_number'] == orderlist[k]]

        axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])

        axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])

        k+=1


查看完整回答
反对 回复 2022-07-05
  • 1 回答
  • 0 关注
  • 111 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信