I am trying to follow this tutorial to make a gauge matplotlib plot and I am able to make three of them. I am wondering how to make them side by side. [I am just following the original code from the 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')
CodePudding user response:
Refactor the gauge
function so it accepts an ax
argument:
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()
Then you can call:
# 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])