Skip to content

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

Closed
@dnicolodi

Description

@dnicolodi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions