Plotting order matters for overlapping colors

When plotting potentially overlapping data points of two different kinds, if both data points have their alpha set to 0.5, I would hope that the resulting color of their overlap is the same regardless of which point was plotted first. This demonstrates that is not the case — instead the color deviates towards the most recently plotted one. This could be an artifact of color theory or something, I’m not sure, but I was wondering what people would have to say about this and possible work-arounds if a direct solution is not possible.


import matplotlib
import numpy as np
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
fig, ax = plt.subplots()

patches = []
colors = [0,1,1,0]
p = PatchCollection(patches,, alpha=0.5)
ax.set_title('Plotting order matters for overlapping colors')

Author: Fantashit

1 thought on “Plotting order matters for overlapping colors

  1. @WingTillDie That is probably because we are blending in to an int8 buffer (rather than a float buffer) which introduces truncation at each composite step (this has way worse issues when overlaying many very transparent objects). The fix is to change the internal agg buffers to use float types rather than ints and cast to int at the very end.

Comments are closed.