Ответ 1
Вы получаете эту ошибку, потому что matplotlib и его объекты полностью не знают о морских функциях.
Передайте объекты осей (т.е. ax1
и ax2
) в seaborn.regplot
или вы можете пропустить определение этих объектов и использовать col
kwarg seaborn.lmplot
С помощью того же импорта предварительное определение ваших осей и использование regplot
выглядит следующим образом:
# create df
x = np.linspace(0, 2 * np.pi, 400)
df = pd.DataFrame({'x': x, 'y': np.sin(x ** 2)})
df.index.names = ['obs']
df.columns.names = ['vars']
idx = np.array(df.index.tolist(), dtype='float') # make an array of x-values
# call regplot on each axes
fig, (ax1, ax2) = plt.subplots(ncols=2, sharey=True)
sns.regplot(x=idx, y=df['x'], ax=ax1)
sns.regplot(x=idx, y=df['y'], ax=ax2)
Использование lmplot требует, чтобы ваш формат данных был аккуратным. Продолжая описанный выше код:
tidy = (
df.stack() # pull the columns into row variables
.to_frame() # convert the resulting Series to a DataFrame
.reset_index() # pull the resulting MultiIndex into the columns
.rename(columns={0: 'val'}) # rename the unnamed column
)
sns.lmplot(x='obs', y='val', col='vars', hue='vars', data=tidy)