繁体   English   中英

类似于 R 的图 python

[英]Graph python similar to R

我有一张这样的表:(忽略列“索引”和“D”)

+-------+-----------------------+----------+----------+----------+
| Index |         Type          |   Male   |  Female  |    D     |
+-------+-----------------------+----------+----------+----------+
|    44 | Life struggles        | 2.097324 | 3.681356 | 1.584032 |
|     2 | Writing notes         | 2.677262 | 3.354730 | 0.677468 |
|    18 | Empathy               | 3.528117 | 4.083051 | 0.554933 |
|    12 | Criminal damage       | 2.926650 | 2.374150 | 0.552501 |
|    20 | Giving                | 2.650367 | 3.196944 | 0.546577 |
|    21 | Compassion to animals | 3.666667 | 4.178268 | 0.511602 |
|    33 | Mood swings           | 2.965937 | 3.451613 | 0.485676 |
|    10 | Funniness             | 3.574572 | 3.104907 | 0.469665 |
|    38 | Children              | 3.354523 | 3.805415 | 0.450891 |
|    47 | Small - big dogs      | 3.221951 | 2.801695 | 0.420256 |
+-------+-----------------------+----------+----------+----------+

我正在尝试做一个类似的图表: 在此处输入图片说明

我知道如何在 R 中实现,但在 python 中不知道

我试过这个:

sns.stripplot(data=df,y="Male",color="Blue")
sns.stripplot(data=df,y="Female",color="red")

在此处输入图片说明

但我不知道如何继续。 有人有我的想法吗?

这很容易用 matplotlib 完成,它只是一个以类别为 y 值的散点图。

plt.style.use('ggplot')
fig, ax = plt.subplots()

ax.plot(df['Male'],df['Type'],'o', color='xkcd:reddish', ms=10, label='Male')
ax.plot(df['Female'],df['Type'],'o', color='xkcd:teal', ms=10, label='Female')
ax.axvline(3,ls='-',color='k')

ax.set_xlim(1,5)
ax.set_xlabel('avg response')
ax.set_ylabel('Variable')
ax.legend(bbox_to_anchor=(0.5, 1.02), loc='lower center',
           ncol=2, title='group')
fig.tight_layout()

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM