以下是我目前的基本代码:
我想把Disease
放在条中
import matplotlib
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
x = [u'Rimegepant',u'Rimegepant',u'Zavegepant',u'Zavegepant',u'Troriluzole',u'Troriluzole',u'Troriluzole',u'Verdiperstat',u'Verdiperstat']
y = [4,3,3,3,2,3,3,3,3]
Disease = ['Acute Treatment of Migraine','Preventive Treatment of Migraine','Acute and Preventive Migraine','Lung Inflammation COVID-19',"Alzheimer's Disease", "OCD", "Spinocerebellar Ataxia", "Multiple System Atrophy", "Amyotrophic Lateral Sclerosis"]
fig, ax = plt.subplots()
width = 0.75 # the width of the bars
ind = np.arange(len(y)) # the x locations for the groups
ax.barh(ind, y, width, color="green", align='edge')
ax.set_yticks(ind+width/2)
ax.set_yticklabels(x, minor=False)
plt.xticks(np.arange(5),('Pre-clinical','Phase I','Phase II','Phase III', 'Approved'))
plt.margins(0,0.05)
plt.title('BHVN')
plt.ylabel('Drug')
plt.show()
您需要更改疾病列表的顺序,以便正确显示
这很好:
您可以通过matplotlib将文本添加到ax,作为
ax.text()
如果你加上
就在代码中的
plt.show()
之前,您将得到:注意,我必须反转你的
Disease
列表(使用[::-1])以使文本显示在你的图像中,否则肌萎缩侧索硬化位于顶部,偏头痛的急性治疗位于底部函数的一般形式是
plt.text(x, y, text)
,因此您可以看到I偏移x 0.1,从条形图中得到y有关该函数的更多信息,请查看matplotlib documentation here
相关问题 更多 >
编程相关推荐