答案 0 :(得分:0)
我想出了办法。这是通过使用两个轴。
from matplotlib import pyplot as plt
import numpy as np
x=np.arange(0,100,2)
fig,ax=plt.subplots(1,2)
ax[1].plot(x,x**2)
ax[0].axis('off')
#add text
ax[0].text(0.3,8000,'High',dict(color='red',fontsize=12))
ax[0].text(0.3,4999,'Medium',dict(color='green',fontsize=12))
ax[0].text(0.3,1666,'Low',dict(color='blue',fontsize=12))
#add bar
ax[0].axvspan(.75, .9, ymin=0, ymax=0.33, alpha=0.5, color='blue')
ax[0].axvspan(.75, .9, ymin=0.33, ymax=0.66, alpha=0.5, color='green')
ax[0].axvspan(.75, .9, ymin=0.66, ymax=0.99, alpha=0.5, color='red')
ax[0].set_ylim(ax[1].get_ylim())
ax[0].set_xlim((0,1))
plt.show()