给出一个像这样的基本数据集:
import pandas as pd
df = pd.DataFrame([
{'sid': 'SID0', 'before': .5, 'after': .8},
{'sid': 'SID1', 'before': .6, 'after': .4},
{'sid': 'SID2', 'before': .2, 'after': .2}
]);
# `before `has max value of 1.0; same for `after`, as these are percentages
绘制之前和之前的差异的方法是什么?分数后?
考虑排除SID并正确显示分布(学生事项的数量;不仅仅是分散绘制分数)。有了SID,我玩了斜率图,但是显示聚合反射并不好。
答案 0 :(得分:1)
IIUC,就像这样(Chainsmokers / Coldplay):
ax = df.set_index('sid').eval('diff = after - before')\
.plot(kind='bar', alpha =1, edgecolor='black', zorder=10)
ax.grid(axis='y', color='k', alpha=.5)
答案 1 :(得分:0)
建议:您可以为每个SID绘制线图。
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame([
{'sid': 'SID0', 'before': .5, 'after': .8},
{'sid': 'SID1', 'before': .6, 'after': .4},
{'sid': 'SID2', 'before': .2, 'after': .2}
]);
df = df.set_index("sid")[['before', "after"]].T
ax = df.plot(marker="o")
ax.set_xlim(-1,2)
ax.set_xticks([0,1])
ax.set_xticklabels(df.index)
plt.show()