График python похож на R - PullRequest
       8

График python похож на R

0 голосов
/ 23 января 2020

У меня есть таблица, подобная этой: (игнорировать столбцы «Индекс» и «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 |
+-------+-----------------------+----------+----------+----------+

, и я пытаюсь сделать аналогичный график: enter image description here

Я знаю, как это сделать в R, но не в python

Я пробовал это:

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

enter image description here

Но я не знаю, как продолжить. У кого-то есть идея?

1 Ответ

4 голосов
/ 23 января 2020

Это легко сделать с помощью 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()

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...