Hi all,

Hopefully the code below is illustrative and commented enough to
clarify my question (also attached if you prefer to download it than
to copy/paste).

Cheers,

f

"""LineCollection ignores alpha value?

The second figure below works, but it sets alpha globally for the whole
collection.  If LineCollection accepts rgbA tuples, why does it ignore the
alpha channel?  Is it possible somehow to have alpha for each line (without
having to make a single-line collection each time?
"""

from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection

# Make two lines
line0 = [(0,0),(1,1)]
line1 = [(1,0),(0,1)]
lines = [line0,line1]

# Make colors for each.  Note alpha is 0.2, so they should be fairly faint, the
# red one is meant to be darker than the blue one
alpha = 0.2
colors = [(0,0,1,alpha),  # blue line
          (1,0,0,2*alpha)]  # red line

# Make a figure with these
f = plt.figure()
ax = f.add_subplot(111)
lc = LineCollection(lines,10,colors)
ax.add_collection(lc)

# Another figure, where we set the alpha globally for the line collection
f = plt.figure()
ax = f.add_subplot(111)
lc = LineCollection(lines,10,colors)
lc.set_alpha(alpha)
ax.add_collection(lc)

plt.show()
"""LineCollection ignores alpha value?

The second figure below works, but it sets alpha globally for the whole
collection.  If LineCollection accepts rgbA tuples, why does it ignore the
alpha channel?  Is it possible somehow to have alpha for each line (without
having to make a single-line collection each time?
"""

from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection

# Make two lines
line0 = [(0,0),(1,1)]
line1 = [(1,0),(0,1)]
lines = [line0,line1]

# Make colors for each.  Note alpha is 0.2, so they should be fairly faint, the
# red one is meant to be darker than the blue one
alpha = 0.2
colors = [(0,0,1,alpha),  # blue line
          (1,0,0,2*alpha)]  # red line

# Make a figure with these
f = plt.figure()
ax = f.add_subplot(111)
lc = LineCollection(lines,10,colors)
ax.add_collection(lc)

# Another figure, where we set the alpha globally for the line collection
f = plt.figure()
ax = f.add_subplot(111)
lc = LineCollection(lines,10,colors)
lc.set_alpha(alpha)
ax.add_collection(lc)

plt.show()
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to