条形图值范围

BarPlot range of values

我想在条形图上绘制以下间隔范围。我该怎么做?

#   • Reggae: Reggae genre has a typical BPM ranging from 60-90
#   • Downtempo: For this genre, it has a typical BPM between 70-100
#   • Chill-Out: This genre has a typical BPM between 90-120
#   • Hip-Hop: This genre has a typical BPM between 85-115
#   • Jazz and Funk: This genre has a typical BPM between 120-125
#   • Pop: For this genre, it has a typical BPM between 100-130
#   • R&B: For this genre, it has a typical BPM between 60-80
#   • Rock: For this genre, it has a typical BPM between 110-140
#   • Metal: This genre has a typical BPM between 100-160

到目前为止我已经这样做了,但是它们从 0 开始我该如何更改代码?

t11 = ['Reggae', 'Downtempo', 'Chill-Out', 'Hip-Hop', 'Jazz and Funk', 'Pop', 'R&B', 'Rock', 'Metal']
t10 = [60, 70,  90,   85, 120, 100, 60, 110, 100]
t12 = [90, 100, 120, 115, 125, 130, 80, 140, 160]


plt.bar(range(len(t12)), t12, align='center')
plt.xticks(range(len(t11)), t11, size='small', rotation=45)

plt.show()

我们可以为柱提供底部和高度,所以让我们根据相应的底部值计算每个柱的高度:

import matplotlib.pyplot as plt
    
t11 = ['Reggae', 'Downtempo', 'Chill-Out', 'Hip-Hop', 'Jazz and Funk', 'Pop', 'R&B', 'Rock', 'Metal']
t10 = [60, 70,  90,   85, 120, 100, 60, 110, 100]
t12 = [90, 100, 120, 115, 125, 130, 80, 140, 160]    

plt.bar(range(len(t12)), height=[h-b for h, b in zip(t12, t10)], bottom=t10, align='center')
plt.xticks(range(len(t11)), t11, size='small', rotation=45)    

plt.tight_layout()
plt.show()

示例输出: