我有以下范围的间隔,我想要绘制在一个酒吧。我该怎么做呢?
# • 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()发布于 2022-03-12 09:51:15
我们可以为条形图提供底部和高度,因此让我们从相应的底部值计算每个栏的高度:
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()样本输出:

https://stackoverflow.com/questions/71448400
复制相似问题