Natasha
Natasha

Reputation: 1521

How to connect the points of a scatterplot with a dashed line?

I've a scatter plot

import matplotlib.pyplot as plt
import numpy as np

x = [(1,0), (0, 1), (2, 1), (3, 1)]
y = [1, 4, 8.5, 17.5]
plt.scatter([str(i) for i in x], y, linestyle='dashed', marker='s')
plt.show()

enter image description here

I tried to use the linestyle key to connect the points by a dashed line. Unfortunately, this didn't work.

Any suggestions on how to do this?

EDIT: I'm using scatter plot for the reason mentioned here

Upvotes: 0

Views: 12130

Answers (1)

Natasha
Natasha

Reputation: 1521

import matplotlib.pyplot as plt
import numpy as np

x = [(1,0), (0, 1), (2, 1), (3, 1)]
y = [1, 4, 8.5, 17.5]
plt.plot([str(i) for i in x], y, linestyle='dashed', marker='s')
plt.show()

Upvotes: 4

Related Questions