0

I am trying to make a scatter plot and scale the size of points on the basis of numbers from a different list.

So I am making a scatter plot of y vs x but the size of each point will depend on the corresponding number from s. Essentially, the larger the value of the element from s bigger would be the point on the scatter plot.

y = [2.2, 3.1, 4.3, 4.9, 5.1]
x = [0.03, 0.3, 0.4, 0.6, 0.7]
s = [48, 134, 391, 203, 193]

fig, ax = plt.subplots()
ax.scatter(x, y)

Any ideas?

Thanks in advance!

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • You may want to check this https://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable – Ivan Calderon Jun 28 '21 at 15:13
  • 1
    [It's in the docs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html?highlight=scatter#matplotlib.axes.Axes.scatter). – Chillie Jun 28 '21 at 15:14
  • @IvanCalderon thanks! Is there any way something similar could be done in 3-D? – thepensioner Jun 28 '21 at 15:16
  • 1
    @VedanthSriram shure, you can check this https://stackoverflow.com/questions/59232073/scatter-plot-with-3-variables-in-matplotlib. But please try to review older questions first before opening new ones with similar topics – Ivan Calderon Jun 28 '21 at 15:22
  • @IvanCalderon - sure. Apologies - I'm new to the site, but I can understand how irritating such questions can be. – thepensioner Jun 28 '21 at 15:26
  • 1
    @VedanthSriram They are not irritating. You just need to get used to how things work in SO, that's all. – Ivan Calderon Jun 28 '21 at 15:31

1 Answers1

1

You are so close

ax.scatter(x, y, s=s)
crayxt
  • 2,367
  • 2
  • 12
  • 17