簡體   English   中英

通過 matplotlib 並排制作儀表圖

[英]Make gauge charts through matplotlib side by side

我正在嘗試按照本教程制作 Gauge matplotlib 圖,並且我能夠制作其中三個。 我想知道如何讓它們並排。 [我只是按照網址中的原始代碼]

gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='something') 

gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='anything') 

gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='nothing') 

重構gauge函數,以便它接受一個ax論點:

def gauge(labels, colors, arrow, title, ax):
    # other code
    # ...

    # remove this
    # fig, ax = plt.subplots()

    # other code

    ax.set_frame_on(False)
    ax.axes.set_xticks([])
    ax.axes.set_yticks([])
    ax.axis('equal')
    # remove this as well
    # plt.tight_layout()

然后你可以調用:

# create the axes
# play with the numbers
fig, axes = plt.subplots(1,3)

gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='something',
      ax=axes[0])

 gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='anything',
      ax=axes[1]) 

gauge(labels=['LOW','MEDIUM','HIGH','EXTREME'], \
      colors=['#007A00','#0063BF','#FFCC00','#ED1C24'], arrow=3, title='nothing',
      ax=axes[2]) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM