Skip to content

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

Closed
acadien opened this issue Oct 14, 2014 · 8 comments
Closed

variable alpha in line collections #3643

acadien opened this issue Oct 14, 2014 · 8 comments

Comments

@acadien
Copy link

acadien commented Oct 14, 2014

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?

@tacaswell
Copy link
Member

You can achieve this effect by passing RGBA tuples for the colors.

@tacaswell tacaswell added this to the unassigned milestone Oct 14, 2014
@acadien
Copy link
Author

acadien commented Oct 14, 2014

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.

@tacaswell
Copy link
Member

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 alpha kwargs is used when the whole artist is composited into the figure and is implemented way up the class stack. Changing how this is handled could turn into a major re-write.

@acadien
Copy link
Author

acadien commented Oct 14, 2014

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.

@tacaswell
Copy link
Member

@acadien That does sound reasonable, I suspect the correct place is in Collection. I don't have the bandwidth to look at that right now, but if you want to that would be great!

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Oct 9, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Nov 8, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@story645 story645 added topic: collections and mappables keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. labels Nov 8, 2023
@story645
Copy link
Member

story645 commented Nov 8, 2023

This is frequently asked for and we allow list alphas in other places

@story645 story645 reopened this Nov 8, 2023
@greglucas
Copy link
Contributor

I'm pretty sure this works now. Adding alpha=np.linspace(0.1, 1, N) to the line collection example: https://matplotlib.org/stable/gallery/shapes_and_collections/line_collection.html shows a blended alpha.
Figure_1

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()

@QuLogic QuLogic modified the milestones: future releases, v3.5.0 Jul 6, 2024
@QuLogic QuLogic removed the keep Items to be ignored by the “Stale” Github Action label Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants