亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在多個子圖上設置相同的軸值?

如何在多個子圖上設置相同的軸值?

慕村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 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號