seaborn带回归线查询的条形图

5us2dqdw  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(350)

我试图用回归线绘制一个条形图。我试图按照之前的建议解决同样的问题,但收到一条我无法克服的错误消息。我的脚本如下:

import seaborn.apionly as sns
import matplotlib.pyplot as plt
import pandas as pd

sns.set(style="white", context="score")

data = {'Days':  ['5', '10', '15', '20'],
        'Impact': ['33.7561', '30.6281', '29.5748', '29.0482']
        }

a = pd.DataFrame (data, columns = ['Days','Impact'])

print (a)

ax = sns.barplot(data=a, x=a.Days, y=a.Impact, color='lightblue' )

# put bars in background:

for c in ax.patches:
    c.set_zorder(0)

# plot regplot with numbers 0,..,len(a) as x value

sns.regplot(x=np.arange(0,len(a)), y=a.Impact, ax=ax)
sns.despine(offset=10, trim=False)
ax.set_ylabel("")
ax.set_xticklabels(['5', '10','15','20'])
plt.show()

我收到的错误消息是:

Traceback (most recent call last):

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\IPython\core\interactiveshell.py", line 3162, in run_cell_async
    self.displayhook.exec_result = result

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\traitlets\traitlets.py", line 604, in __set__
    self.set(obj, value)

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\traitlets\traitlets.py", line 578, in set
    new_value = self._validate(obj, value)

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\traitlets\traitlets.py", line 610, in _validate
    value = self.validate(obj, value)

  File "C:\Users\david\AppData\Local\Programs\Spyder\pkgs\traitlets\traitlets.py", line 1842, in validate
    if isinstance(value, self.klass):

TypeError: isinstance() arg 2 must be a type or tuple of types

ERROR! Session/line number was not unique in database. History logging moved to new session 54

但我不确定这意味着什么。有人能帮忙吗?

lo8azlld

lo8azlld1#

请确保供应 intfloatdf ```
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

data = {'Days': [5, 10, 15, 20],
'Impact': [33.7561, 30.6281, 29.5748, 29.0482]
}

a = pd.DataFrame (data, columns = ['Days','Impact'])

print (a)

ax = sns.barplot(data=a, x='Days', y='Impact', color='lightblue' )

put bars in background:

for c in ax.patches:
c.set_zorder(0)

plot regplot with numbers 0,..,len(a) as x value

ax = sns.regplot(x=np.arange(0,len(a)), y=a['Impact'], marker="+")
sns.despine(offset=10, trim=False)
ax.set_ylabel("")
ax.set_xticklabels(['5', '10','15','20'])
plt.show()

![](https://i.stack.imgur.com/b9U5E.png)

相关问题