【发布时间】:2018-12-02 02:21:14
【问题描述】:
根据解释为什么这个问题和这个link不同
据我了解,此链接从图表中获取高度,但在我的情况下,图表中根本没有 numpatients6month 这一列,我只是在数据框中有它。
所以我有一个条形图。它为每个x-axis 包含两个条形图,其中每个条形图从不同的数据帧中读取。
这是我绘制条形图的代码。
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['axes.prop_cycle'] = ("cycler('color', 'rg')")
dffinal['CI-noCI']='Cognitive Impairement'
nocidffinal['CI-noCI']='Non Cognitive Impairement'
res=pd.concat([dffinal,nocidffinal])
sns.barplot(x='6month',y='final-formula',data=res,hue='CI-noCI').set_title(fs)
plt.xticks(fontsize=8, rotation=45)
plt.show()
如您所见,有two data frame。我用颜色green 和nocidffinal 用颜色red 绘制dffinal。
这是情节的结果:
更多解释:dffinal是基于(6month, final-formula)nocidffinal也是基于(6month,final-formula)。
这是我的nocidffinal 数据框:
6month final-formula numPatients6month
137797.0 1 0.035934 974
267492.0 2 0.021705 645
269542.0 3 0.022107 769
271950.0 4 0.020000 650
276638.0 5 0.015588 834
187719.0 6 0.019461 668
218512.0 7 0.011407 789
199830.0 8 0.008863 677
269469.0 9 0.003807 788
293390.0 10 0.009669 724
254783.0 11 0.012195 738
300974.0 12 0.009695 722
和dffinal:
6month final-formula numPatients6month
166047.0 1 0.077941 680
82972.0 2 0.057208 437
107227.0 3 0.057348 558
111330.0 4 0.048387 434
95591.0 5 0.033708 534
95809.0 6 0.036117 443
98662.0 7 0.035524 563
192668.0 8 0.029979 467
89460.0 9 0.009709 515
192585.0 10 0.021654 508
184325.0 11 0.017274 521
85068.0 12 0.010438 479
如您所见,此数据框中有 numPatients6month 列,我想将其显示在每个条形图的顶部。
我确实NOT 想要更改条形图并根据此列对其进行分组,而不是我只想将此数字作为额外信息显示给每个条形顶部的用户。
感谢您的宝贵时间:)
【问题讨论】:
-
@ImportanceOfBeingErnest 你能取消标记为重复吗?我添加了解释它与您的链接有何不同!!!
-
我重新打开了。我认为您还应该添加this question 没有帮助的程度。
-
@ImportanceOfBeingErnest 确定我会添加更多信息,因为我尝试了我在堆栈中找到的三种不同的东西。谢谢:)
标签: pandas matplotlib visualization seaborn data-analysis