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

swfiua at gmail.com swfiua at gmail.com
Mon Dec 5 19:39:01 EST 2022


This code produces plots that look ok to me:

from matplotlib import pyplot as plt

import numpy as np

x = np.random.randint(1,100, 100)
y = np.random.randint(1,100, 100)
z = np.random.randint(1,100, 100)

fig, ax = plt.subplots()
splot = ax.scatter(x, y,  marker= 'o',
                   s = z,
                   cmap ='viridis_r', c = z)
fig.tight_layout()
plt.colorbar(splot)
plt.show()


On Mon, 5 Dec 2022 at 03:08, Gautham <gautham949 at gmail.com> wrote:

> 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
>>
>>
>
> --
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/matplotlib-users/attachments/20221205/4a2482be/attachment.html>


More information about the Matplotlib-users mailing list