【发布时间】:2020-01-24 20:34:11
【问题描述】:
我正在尝试使用来自Pandas DataFrame 的数据来绘制类似的图。日期是 0 到 100 之间的数字,代表百分比。我有 3 列代表 3 个不同的类别,每个类别都有百分比值。
我想得到什么:
我使用这段代码得到了什么:
df_margins = pd.read_excel("path to excel file")
df_margins.reset_index(drop=True, inplace=True)
df_margins_sort = pd.DataFrame(np.sort(df_margins.values, axis=0), index=df_margins.index, columns=df_margins.columns)
df_margins_sort.hist( alpha=0.5)
尝试使用 seaborn 库我得到了这个:
x = df_margins_sort["safety_margin_distribution_0"].tolist()
y = df_margins_sort["safety_margin_distribution_5"].tolist()
z = df_margins_sort["safety_margin_distribution_10"].tolist()
ggg = [x,y,z]
fig, ax = plt.subplots()
for a in ggg:
sns.distplot(a, bins=range(1, 100, 10), ax=ax, kde=False)
ax.set_xlim([0, 100])
79.6657 8.3008 12.0334
28 72 0
51.4077 48.5923 0
84.1176 2.7451 13.1373
79.5455 1.0101 19.4444
51.9205 48.0795 0
57.2877 6.5906 36.1217
71.2589 11.4014 17.3397
56.2624 43.7376 0
76.4228 0 23.5772
51.8473 6.6502 41.5025
74.8555 25.1445 0
85.8254 14.1746 0
63.2754 0.7444 35.9801
【问题讨论】:
-
请以文本形式包含您的数据。
-
@QuangHoang 将数据添加为文本。
-
第二个情节有什么问题?
-
@PaulH 在第二个图中看起来我有超过 3 个类别。另外,我想避免使用 seaborn。
标签: python pandas matplotlib histogram