Skip to content

[Bug]: Inconsistency in how markers with alpha != 1 are rendered in the PDF backend #21345

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
dnicolodi opened this issue Oct 13, 2021 · 3 comments

Comments

@dnicolodi
Copy link
Contributor

dnicolodi commented Oct 13, 2021

Bug summary

Using the Qt5Agg or most other backends, when drawing a filled marker with alpha < 1 the marker edge line overlaps with the marker face patch thus naturally creating a (IMHO nice) effect where the semi-transparent filled marker is surrounded by a less transparent edge line. This is visible in a few examples in the gallery, for example:

https://matplotlib.org/stable/gallery/shapes_and_collections/scatter.html#sphx-glr-gallery-shapes-and-collections-scatter-py
https://matplotlib.org/stable/gallery/lines_bars_and_markers/scatter_symbol.html#sphx-glr-gallery-lines-bars-and-markers-scatter-symbol-py

However, when saving one of these plots in PDF format, this overlap between edge line and marker patch is gone.

I tried to find a way to obtain the darker edge effect in a PDF either by specifying parameters to the plt.scatter() function or by overlapping multiple scatter plots with different parameters, but so far I haven't found a work-around.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2
plt.figure()
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
plt.savefig('test.pdf')
plt.savefig('test.png')

Actual outcome

Capture

PDF as rendered by Microsoft Edge. Adobe Acrobat reader renders it in the same way.

Expected outcome

test_scatter

The same plot saved in PNG format.

Operating system

Windows

Matplotlib Version

3.4.2

Matplotlib Backend

No response

Python version

3.8.8

Jupyter version

No response

Other libraries

No response

Installation

conda

Conda channel

No response

@anntzer
Copy link
Contributor

anntzer commented Oct 13, 2021

I think this is similar to #10035?

@jklymak
Copy link
Member

jklymak commented Oct 13, 2021

Yeah, I was trying to find that, but failed somehow. Lets keep conversation there, unless this is really unique.

@dnicolodi
Copy link
Contributor Author

Yes, definitely @anntzer. I spent quite some time trying to find an existing ticket for the issue but I wasn't unable to find it.

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

3 participants