You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Weird behaviour in scatter plot with small markersize and small alpha #4322
I was trying to get a feel for the look of a scatterplot with many small markers and low alpha. I used the following script to produce some tests:
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import numpy as np
N = int(5e5)
nrows = 4
ncols = 4
xmin = -6
xmax = 6
ymin = xmin
ymax = xmax
figs, axes = plt.subplots(nrows = nrows, ncols = ncols, figsize = (2*ncols, 2*nrows))
x = np.random.normal(loc = 0, scale = 0.5, size = N)
y = np.random.normal(loc = 0, scale = 0.5, size = N)
alpha = lambda i : 0.01 + 0.005*i
s = lambda i : 0.01 + 0.005*i
for i in range(ncols):
for j in range(nrows):
axes[i,j].set_title('alpha = %s, s = %s' % (alpha(j), s(i)), size = 8)
axes[i,j].scatter(x, y, marker = '.', edgecolor = '', color = 'k', lw = 0, alpha = alpha(j), s = s(i))
axes[i,j].set_xlim((xmin, xmax))
axes[i,j].set_ylim((ymin, ymax))
axes[i,j].set_xticklabels([])
axes[i,j].set_yticklabels([])
plt.suptitle('N = %s' % N)
plt.savefig('scattertest.png', dpi = 600)
First, I plotted 500.000 markers, and got this result, showing how the scatter plots look with different combinations of size and alpha:
Then, I thought it's weird that some of the combinations just don't show up at all, so I tried increasing the number of markers to 1.000.000. The only change I made in the script was to change 5e5 to 1e6, yet now the plot is empty.
Then, I somewhat randomly commented out the line
plt.suptitle('N = %s' % N)
and again made no other changes, and now the plot is no longer empty (but still, some combinations of s and alpha just don't show up).
Is it expected that some combinations of small size and low alpha should lead to invisible markers?
Why does a seemingly irrelevant thing like a plot title change whether markers show up or not?
I'm using matplotlib version 1.4.2 (installed with pip), and python 3.4.2.
I think what you're seeing is an instance of #3371. The issue is that the image buffer only using 8-bits of alpha, and so really small values round down to zero after premultiplication. The solution is to allow an option to use floating-point image buffers. Agg is really close to having support for that (they currently claim they do) but it's broken and progress seems slow. I've spent some time looking into it, and unfortunately it's really hard to make heads or tails of the Agg code base.
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!
Activity
mdboom commentedon Apr 10, 2015
I think what you're seeing is an instance of #3371. The issue is that the image buffer only using 8-bits of alpha, and so really small values round down to zero after premultiplication. The solution is to allow an option to use floating-point image buffers. Agg is really close to having support for that (they currently claim they do) but it's broken and progress seems slow. I've spent some time looking into it, and unfortunately it's really hard to make heads or tails of the Agg code base.
github-actions commentedon Mar 11, 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!
chahak13 commentedon Mar 15, 2023
Haven't dug deep but I don't think this is an issue anymore. The code plots this now
If someone who had more idea about the issue can confirm, maybe we can close this?
QuLogic commentedon Apr 12, 2023
I can't reproduce on either
mainorv2.0.0, and I don't want to bisect any further back than that, but it seems fixed.