Я хочу добавить график регрессии к линейному графику с соответствующими цветами. Я перебираю данные и передаю цвета seaborn.regplot
. Хотя значения для оси x всегда одинаковы, функция генерирует графики с разными диапазонами, что выглядит беспорядочно. Как я могу настроить диапазоны так, чтобы они все были равны?
%pylab inline
import pandas as pd
from seaborn import regplot
timetable_template = pd.DataFrame({'2000': [1, 2, 3, 4],
'2001': [7, 2, 3, 3],
'2002': [6, 3, 2, 5],
'2006': [1, 0, 5, 8]}, index=['R', 'S', 'I', 'N'] )
markers = ['s']*4
def _timeplot(timetable, plot_reg=True, ax=None):
if ax is None:
ax = plt.gca()
df = timetable.copy()
df.columns = [int(i) for i in df.columns]
dfT = df.T
lw = .5
if plot_reg:
lw = 0
for i, col in enumerate(dfT.columns):
x, y = list(dfT[col].index), dfT[col].values
last_plot = plt.plot(x, y, marker=markers[i], lw=lw, label=col)
if plot_reg:
color = last_plot[0].get_color()
regplot(x, y, color=color, ax=ax, line_kws={'lw': 0.5})
plt.legend()
plt.xticks([int(i) for i in df.columns])
return df
_timeplot(timetable_template, plot_reg=True)
![enter image description here](https://i.stack.imgur.com/3R0b6.png)