user12536200
user12536200

Reputation:

Overlaying/Superimposing plots in matplotlib

I have three scatter plots, with marker colors as red, green and blue.

The points are placed at the same position(x,y) in all the three plots but may have different marker size.

I want to superimpose these three plots over each other such that each point has the 3 colors 'added'.

For example: if a particular point has the same area in all three plots, it should appear white.

I tried using plt.scatter() three times, but this results in one plot getting plotted over another, that is, the scatter plot plotted the last appears over those which were plotted before it.

Any way to overcome this?

Upvotes: 0

Views: 839

Answers (1)

warped
warped

Reputation: 9491

You can use transparency and different sizes to make the overlap come out:

import matplotlib.pyplot as plt

datapoints = [(1,1), (1,1), (1,1), (1.1,1.1)]
sizes = [20000,1000,5000,2000]

# plot datapoints with different sizes:
for d, s in zip(datapoints, sizes):
    plt.scatter(*d, s=s, alpha=0.3)

If you really need additive blending, you should check out this post.

enter image description here

Upvotes: 1

Related Questions