0

I have the following code sample, where I need to draw a green line, as shown inside the plot below:

fig = plt.figure(figsize = (12,6))
plt.scatter((y - y_pred), y_pred , color = 'red')
plt.axhline(y=0, color='r', linestyle=':')
plt.ylim(0,50)
plt.xlim(-4,6)
p = sns.lineplot([-4,6],[25,25],color='g')
plt.ylabel("Predictions")
plt.xlabel("Residual")
p = plt.title('Homoscedasticity Check')
plt.show()

enter image description here

Although the code above worked some time back, it doesn't seem to execute now, and I observe the following error:

TypeError: lineplot() takes from 0 to 1 positional arguments but 2 were given

What could be wrong here ? For example, what is the right format to indicate where the Green line should appear ?

Dinesh
  • 654
  • 2
  • 9
  • 31

1 Answers1

2

The reason for the error is that, from seaborn version 0.12 onwards, "the only valid positional argument will be data, and passing other arguments without an explicit keyword will result in an error or misinterpretation". So, what might have worked earlier will not work now. To make the same code work, you need to replace sns.lineplot(...) with below code.

x=[-4,6]
y=[25,25]
p = sns.lineplot(x=x,y=y,color='g')

However, as you have already used in the code, axhline() is the easier and better way to draw horizontal line... like below

plt.axhline(y=25, color='g', linewidth=3)
Redox
  • 9,321
  • 5
  • 9
  • 26