-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Maximum Alpha for Scatter #28284
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
This is going to be very hard to achieve with the way Matplotlib is architected. We send markers for the renderer and ask it to put them in the image. We don't compose the result, so we can't control the color of individual pixels in the final output. Something that would be possible with our model is to rasterize each scatter call and then add an alpha for the raster of all the points before putting it on the parent raster. But that would be a complex API that I would not hold my breath to see implemented. As you are finding - at some point scatter with alpha becomes impractical and you may want to consider other methods like 2D histogramming. |
To add a bit more detail, when we rasterize the output we composite the layers one at a time and the updated color of a pixel is
so we do not have access to the history of why the pixel we are updating is the color it is so we can not dynamically turn down the alpha. I am not aware of this ability existing in svg or pdf (the vector formats we support that also support alpha at all) so even if we could come up with a way to do this in Agg (which I do not think is possible without major changes), it would still be a heavy lift to get into Matplotlib as we try to keep the backends as feature parity as possible. |
@tacaswell @jklymak Thank you guys for the Insights! I also appreciate the Input for separate Ideas to try ;) |
Actually there are some tricks that can be played using agg_filter: from pylab import *
x0, y0, x1, y1 = rand(4, 5000) # Fake data.
# The default case.
figure()
scatter(x0, y0, alpha=.5)
scatter(x1, y1, alpha=.5)
# Rescale alpha by 0.8. Perhaps not the best, but that's the idea...
def rescale_alpha_filter(im, dpi):
im[..., 3] *= .8 # Decrease alpha.
return im, 0, 0
figure()
scatter(x0, y0, alpha=.5, agg_filter=rescale_alpha_filter)
scatter(x1, y1, alpha=.5, agg_filter=rescale_alpha_filter)
show() On a vector backend this will lead to the artists getting rasterized, but I guess this is connected to the idea of adding support for knockout groups (#26971 (comment)), which I think may be supported by at least some vector formats. (A proper design would require looking into what svg/pdf/ps actually supports and take it from there :-)) |
Just had a crazy idea, but could we utilize such a feature to help
eliminate those conflation artifacts when plotting neighboring polygons
like fron contourf() with an alpha != 1.0?
…On Mon, May 27, 2024 at 7:23 AM Antony Lee ***@***.***> wrote:
Actually there are some tricks that can be played using agg_filter:
from pylab import *
x0, y0, x1, y1 = rand(4, 5000) # Fake data.
# The default case.figure()scatter(x0, y0, alpha=.5)scatter(x1, y1, alpha=.5)
# Rescale alpha by 0.8. Perhaps not the best, but that's the idea...
def rescale_alpha_filter(im, dpi):
im[..., 3] *= .8 # Decrease alpha.
return im, 0, 0
figure()scatter(x0, y0, alpha=.5, agg_filter=rescale_alpha_filter)scatter(x1, y1, alpha=.5, agg_filter=rescale_alpha_filter)
show()
On a vector backend this will lead to the artists getting rasterized, but
I guess this is connected to the idea of adding support for knockout groups
(#26971 (comment)
<#26971 (comment)>),
which I think may be supported by at least some vector formats. (A proper
design would require looking into what svg/pdf/ps actually supports and
take it from there :-))
—
Reply to this email directly, view it on GitHub
<#28284 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6C3CZMLIIAA6MYHF3LZEMJT7AVCNFSM6AAAAABIFNLLT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZTGI3DOMZZHA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
It is not clear to me how this could help, but I'm all ears. |
The conflation artifacts happen when the boundaries of two polygons with an
alpha < 1 occupy the same pixel. So, their alphas basically add up, right?
But, if we could enforce a maximum alpha equal to the alpha of the original
polygon, then wouldn't it help subdue the conflation effect? I'm
hand-waving the math in my head, so it might not actually work out quite
right, but at least the transparency will be uniform, right?/
…On Sat, Jun 1, 2024 at 4:02 PM Antony Lee ***@***.***> wrote:
It is not clear to me how this could help, but I'm all ears.
—
Reply to this email directly, view it on GitHub
<#28284 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6GBZBGEHLY3PRR6YKDZFISEZAVCNFSM6AAAAABIFNLLT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTGU3DONZXG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Problem
When Overlaying multiple sets using scatter and alpha a previously plotted set can become occluded entirely if the density is too high as the summed alpha goes to full occlusion.
Using low alphas for pointclouds leads to outliars being *almost invisible.
Objective:
Introduce a parameter to cap the maximum alpha value in scatter plots to maintain visibility of underlying sets when overlaying multiple point clouds.
Use Case:
Overlaying point clouds from different datasets without obscuring underlying data, avoiding the need to manipulate z-order.
Implementation Details
Benefits
Enhanced Visualization: Maintains clarity and readability of plots with multiple overlaid datasets.
Flexibility: Users can control transparency to prevent complete opacity in densely populated areas.
Example Usage
import matplotlib.pyplot as plt
Sample data
x1, y1 = [1, 2, 3], [4, 5, 6]
x2, y2 = [2, 3, 4], [5, 6, 7]
Scatter plot with max_alpha
plt.scatter(x1, y1, alpha=0.5, max_alpha=0.8)
plt.scatter(x2, y2, alpha=0.5, max_alpha=0.8)
plt.show()
Conclusion
Implementing a max_alpha parameter in Matplotlib’s scatter plot functionality will provide greater control over data visualization, ensuring that underlying datasets remain visible even when multiple layers are overlaid.
Proposed solution
No response
The text was updated successfully, but these errors were encountered: