Ivan
Ivan

Reputation: 23

How to send highest matplotlib scatter plot c-values to front?

I have a pandas dataframe of 3 columns (x, y, z) which I plot using a scatter plot with z-variable assigned to the c-value, with the resulting image

Variables x, y, and z are all continuous real data and z != f(x,y). I'm unable to provide the actual data sample.

As you can see the points overlap, and highest values are hidden from view.

I would like this plot to display the highest (red) points on top of the lowest (blue points) to produce an intensity plot similar to this

I assume this is achieved by somehow controlling the plot order of z, and I have tried sorting the dataframe by the z-variable with no success.

I would appreciate some method for the existing chart or a suggestion for a new chart to make this possible.

Upvotes: 2

Views: 1066

Answers (1)

Simon Rogers
Simon Rogers

Reputation: 344

Try with this

df = pd.DataFrame(data={'x': [0.2, 0.21, 0.22],
                        'y': [0.2, 0.21, 0.22],
                        'z': [1.8, 2, 3]})

df.plot.scatter('x','y',c='z', s=5000)

Then with this

df.sort_values('z', ascending=False, inplace=True)

df.plot.scatter('x','y',c='z', s=5000)

The z order is reversed between the two

Upvotes: 3

Related Questions