 # color and transparency in overlapping regions

Dear all,

I want to plot 3 overlapping regions using fill() into one panel, but my
solution looks sort of messy... Here is the code:

···

===
import matplotlib.pyplot as plt
import scipy

# ##Data to plot seq = scipy.sin(range(0,10)) xpts = scipy.concatenate((range(0,10), range(0,10)[::-1])) plt.figure() ##Plot 3 overlapping regions, a different color for each one for diff, color in zip([1,2,3], ["blue", "red", "yellow"]):     ypts = scipy.concatenate((seq - diff, (seq - diff * 2)[::-1]))     plt.fill(xpts, ypts, alpha=0.4, fc=color, ec="black", lw=2, label=str(diff)) plt.legend() plt.show()

The figure looks like 4 regions are plotted, because overlapping red and
yellow make an orange region... I tried some different combination, but
it never looked good. Does anybody have an idea how to chose the colors
and 'alpha' values for transparency so that the plot looks good and
could be printed?

Any help is appreciated,
Hannes

Dear all,

I want to plot 3 overlapping regions using fill() into one panel, but my
solution looks sort of messy... Here is the code:

[...snip...]

The figure looks like 4 regions are plotted, because overlapping red and
yellow make an orange region... I tried some different combination, but
it never looked good. Does anybody have an idea how to chose the colors
and 'alpha' values for transparency so that the plot looks good and
could be printed?

Any help is appreciated,
Hannes

Hi Hannes,

maybe hatching of the regions help to distinguish the 3 different regions of 4
regions (see the code below).

Kind regards,
Matthias

···

On Tuesday 13 April 2010 16:37:21 hettling wrote:

=======
from matplotlib import pyplot as plt
import numpy as np

##Data to plot
seq = np.sin(range(0, 10))
xpts = np.concatenate((range(0, 10), range(0, 10)[::-1]))

plt.figure()
##Plot 3 overlapping regions, a different color for each one
for diff, color, hatch in zip([1, 2, 3], ["blue", "red", "yellow"],
['/', '|', '\\']):
ypts = np.concatenate((seq - diff, (seq - diff * 2)[::-1]))
plt.fill(xpts, ypts, alpha=0.7, fc=color, hatch=hatch, ec="black",
lw=2, label=str(diff))