【发布时间】:2015-09-12 08:24:24
【问题描述】:
我有以下数据框:
strterminationreason total_trials %Trials
0 Completed, Negative outcome/primary endpoint(s... 3130 6.390624
1 Completed, Outcome indeterminate 3488 7.121565
2 Completed, Outcome unknown 6483 13.236555
3 Completed, Positive outcome/primary endpoint(s... 15036 30.699498
4 Terminated, Business decision - Drug strategy ... 526 1.073952
5 Terminated, Business decision - Other 1340 2.735922
6 Terminated, Business decision - Pipeline repri... 1891 3.860917
7 Terminated, Early positive outcome 231 0.471640
8 Terminated, Lack of efficacy 1621 3.309649
9 Terminated, Lack of funding 533 1.088244
10 Terminated, Other 1253 2.558291
11 Terminated, Planned but never initiated 4441 9.067336
12 Terminated, Poor enrollment 3201 6.535587
13 Terminated, Safety/adverse effects 993 2.027441
14 Terminated, Unknown 4811 9.82277
我使用以下代码水平绘制条形图,因为正常的不适合上面的文本代码。
df['%Trials']=(df.ix[:,1]/sum(df.ix[:,1]))*100
plt.figure(figsize=(35,20))
plt.barh(df.ix[:,2],df.index,align='edge')
plt.xlim([0,31])
plt.yticks(df.index, df.strterminationreason)
plt.ylabel("TerminationReason",fontsize=20)
plt.xlabel("%Trials",fontsize=20)
但我得到的输出是条形范围不反映数据框中的实际 % 值。就像最高百分比是完成的,积极的结果/主要终点,但它不显示相同。知道为什么吗?
还有人知道如何正确调整每个条形下方的文本,以便没有重叠且干净。
【问题讨论】:
-
请检查
barh的参数顺序:matplotlib.pyplot.barh(bottom, width, height=0.8, left=None, hold=None, **kwargs)--bottom是条形的 y 坐标,width是 x 轴上条形的宽度 -
不明白。你能帮忙吗?
标签: python pandas matplotlib