-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
variable alpha in line collections #3643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can achieve this effect by passing RGBA tuples for the colors. |
I don't know why I didn't think of this, thanks for pointing it out. Regardless it would be nice to have the alpha interface when passing in a color map and array. |
One difficulty with that has to do with the underlying mechanisms of the AGG rastering. As I understand it (and I am not super familiar with that bit of code so I could be wrong), the |
Just a thought but a switch could be added somewhere in the class chain that catches if alpha is an array and constructs the corresponding rgba values array from the cmap. |
@acadien That does sound reasonable, I suspect the correct place is in |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This is frequently asked for and we allow list alphas in other places |
I'm pretty sure this works now. Adding import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import LineCollection
N = 50
x = np.arange(N)
ys = [x + i for i in x] # Many sets of y to plot vs. x
segs = [np.column_stack([x, y]) for y in ys]
fig, ax = plt.subplots()
ax.set_xlim(np.min(x), np.max(x))
ax.set_ylim(np.min(ys), np.max(ys))
line_segments = LineCollection(segs, array=x,
linewidths=(0.5, 1, 1.5, 2),
linestyles='solid',
alpha=np.linspace(0.1, 1, N))
ax.add_collection(line_segments)
axcb = fig.colorbar(line_segments)
axcb.set_label('Line Number')
ax.set_title('Line Collection with mapped colors')
plt.sci(line_segments) # This allows interactive changing of the colormap.
plt.show() |
A line collection can have variable line width, face color, edge color, antialiasing, and offests but the alpha is fixed. It seems odd that so much variation is possible except when it comes to transparency. This is a headache to deal with when plotting a large number of line segments, would it be possible to make the alpha variable accept a list instead of a single float?
The text was updated successfully, but these errors were encountered: