GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Add blend modes that maximize/minimize the pixel coverage by ayshih · Pull Request #32469 · matplotlib/matplotlib Conversation
Contributor
PR summaryThis PR adds two new blend modes, which provide alternatives when alpha values represent pixel coverage rather than opacity. These blend modes are supported by only the Agg backend (and vector backends through rasterization). Alpha is the combination of both opacity (i.e., transparency) and pixel coverage (the fraction of the pixel that is filled in with a color). In matplotlib, the alpha values along antialiased edges of patches is determined by calculating the pixel coverage. Importantly, once the alpha for a pixel is represented as a single number, there is no longer any geometric information about which part of the pixel is actually covered. When alpha represents opacity, the existing blend modes have the desired output. When alpha represents pixel coverage, the behavior of the PDF blend modes is equivalent to assuming that the part of the source pixel that is covered and the part of the destination pixel that is covered are unrelated/independent. However, that assumption is broken when two patches intentionally share an edge:
The two new blend modes in this PR are:
This PR is an outgrowth of #32256, which currently uses the "plus" blend mode, but would behave better with the "min cover" blend mode in those situations when a collection of contiguous patches can also have overlapping of patches (e.g., as a result of a projection down from 3D space). Example
import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Ellipse, Polygon, Rectangle fig, axs = plt.subplots(1, 5, figsize=(7, 3), layout="constrained") fig.set_facecolor("none") for ax, blend_mode in zip(axs, ["normal", "plus", "min cover", "knockout", "max cover"]): ax.set_facecolor("none") # Exactly overlapping ellipses that share an antialiased edge ax.add_patch(Ellipse((0.5, 1.8), 1, 0.4, fc="m", ec="none")) ax.add_patch(Ellipse((0.5, 1.8), 1, 0.4, fc="y", ec="none", blend_mode=blend_mode)) # Exactly adjacent patches with a shared antialised edge ax.add_patch(Polygon(np.array([[0, 0, 0.3, 0.9, 1], [1, 1.5, 1.1, 1.3, 1]]).T, fc="purple", ec="none")) ax.add_patch(Polygon(np.array([[0, 0.3, 0.9, 1, 1], [1.5, 1.1, 1.3, 1, 1.5]]).T, fc="purple", ec="none", blend_mode=blend_mode)) # Overlapping rectangles with a variety of alpha combinations ax.add_patch(Rectangle((0, 0.7), 1, 0.1, fc="b", ec="none", alpha=1)) ax.add_patch(Rectangle((0, 0.5), 1, 0.2, fc="b", ec="none", alpha=0.5)) ax.add_patch(Rectangle((0, 0.1), 1, 0.2, fc="lime", ec="none", alpha=0.5)) ax.add_patch(Rectangle((0, 0), 1, 0.1, fc="lime", ec="none", alpha=1)) for rx, alpha in zip([0.1, 0.4, 0.7], [0.3, 0.5, 0.7]): ax.add_patch(Rectangle((rx, -0.1), 0.2, 1, fc="b", ec="none", alpha=alpha, blend_mode=blend_mode)) ax.set_title(blend_mode) ax.set_xlim(-.1, 1.1) ax.set_ylim(-.1, 2.1) ax.set_aspect("equal") ax.set_axis_off() plt.show() AI DisclosureNo AI was used PR quality check
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThis branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabelsProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |