通过matplotlib并排制作仪表图表

2024-09-28 20:54:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着按照这个tutorial来做一个测量matplotlib图,我能做三个。我想知道如何使它们并排排列。[我只是在遵循url中的原始代码]

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') 

Tags: 代码urllabelstitlematplotlibtutoriallowmedium
1条回答
网友
1楼 · 发布于 2024-09-28 20:54:40

重构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]) 

相关问题 更多 >