[Matplotlib-users] How to match color bar in scatter plot with the value of scatter point size?

Gautham gautham949 at gmail.com
Mon Dec 5 03:07:41 EST 2022


I should mention that I iterate through a set of x,y, and z arrays and add
the color plot outside the loop.

fig, ax = plt.subplots()
for x, y, z in arrays:
     splot = ax.scatter(x.to_numpy(), y.to_numpy(),  marker= 'o', s =
z.to_numpy(), cmap ='viridis_r', c = z.to_numpy())

fig.tight_layout()
plt.colorbar(splot)
plt.show()

Gautham

On Mon, Dec 5, 2022 at 11:55 AM Gautham <gautham949 at gmail.com> wrote:

> Hello all,
>
> I am trying to generate a scatter plot using dataframe series *x *&* y*
> and the size of the scatter data point using dataframe series *z*.
>
> All is good until I add the color bar, which maps the data in *z*. The
> resulting plot doesn't make sense to me as the color of the scatter points
> is all over the plot regardless of the size of scatter data points.
>
> Example script:
>
> fig, ax = plt.subplots()
> splot = ax.scatter(x.to_numpy(), y.to_numpy(),  marker= 'o', \
>                   s = scat.to_numpy(), cmap ='viridis_r', c =
> scat.to_numpy())
> fig.tight_layout()
> plt.colorbar(splot)
> plt.show()
>
> Thanks
> Gautham
>
>

--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/matplotlib-users/attachments/20221205/5146e44c/attachment.html>


More information about the Matplotlib-users mailing list