0

I have two lists:

x = [5, 5, -5, -5, 10, 10, -10, -10, 15, 15, -15, -15, 20, 20, -20, -20]
y = [-5, 5, 5, -10, -10, 10, 10, -20, -15, 15, 15, -30, -20, 20, 20, -40]

plotting the points:

import matplotlib.pyplot as plt
plt.scatter(x, y)

I get:

enter image description here

but when I want to connect the points, I get:

plt.scatter(x, y, "-")

TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

henry
  • 875
  • 1
  • 18
  • 48

2 Answers2

1

Scatter plot just plots the dots, if you want to connect them. You can use plot() function with same arguments of scatter

plt.scatter(x,y)
plt.plot(x, y)
plt.show()
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41
1

If you want a connected line, you should only use plt.plot(x,y, '-o').

The purpose of a scatter plot, as the name suggests, is to show you a cloud of points which can give a visual sense about how two datasets are correlated independently of the order of the points (pairs). That's why plt.scatter does not support line connection of points.

On the other hand,when you plot with lines using plt.plot, then you can visually follow the order of the pairs and it is useful for instance when visualizing time series.

JacoSolari
  • 1,226
  • 14
  • 28