Skip to content

Hide fully transparent text in PS output. #10166

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

Merged
merged 1 commit into from
Jan 6, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 4, 2018

PS doesn't really support transparency (because the format itself
doesn't, unless using some nonstandard extensions), but has some special
casing for "fully transparent" (see e.g. "rgbFace is None" check in
_draw_ps).

Also implement the special-casing for text.

Closes #10163.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the ps-fully-transparent-text branch from 3daceff to 7a9e51c Compare January 4, 2018 21:19
@@ -148,3 +149,13 @@ def test_determinism_all():
def test_determinism_all_tex():
"""Test for reproducible PS/tex output"""
_determinism_check(format="ps", usetex=True)


@image_comparison(baseline_images=['canonical'], extensions=["ps"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my knowledge, is there a reason to use single quotes for 'canonical' but double quotes for "ps" here?

Copy link
Contributor Author

@anntzer anntzer Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waves his hand repeat after me: "This typo never existed"

def test_transparency():
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
# Reuse a standard test image, but chec that some additional transparent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above

@anntzer anntzer force-pushed the ps-fully-transparent-text branch from 7a9e51c to 0491b56 Compare January 4, 2018 21:27
Copy link
Contributor

@afvincent afvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a reasonable fix to me :) but I am no PS expert.

A (very) minor point is still itching me a bit: IIUC, with this fix, transparent text objects will not be present at all in the resulting PS file. So, it will not be possible anymore to modify these text objects afterwards directly in the PS file, will it not? I do not have a peculiar use case in mind, I just want to be sure that we do not overlook some behavior that might be useful to a few users.

fig, ax = plt.subplots()
ax.set_axis_off()
ax.plot([3, 2, 1], alpha=0)
ax.text(.5, .5, "foo", alpha=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advise to put the text in the drawn area ([0, 2]x[1, 3], +/- the default margins). Something like ax.text(0.5, 1.5, "foo", alpha=0). Otherwise, the text instance is not visible, even with a non null alpha value, is it not?

Copy link
Contributor Author

@anntzer anntzer Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed

@anntzer
Copy link
Contributor Author

anntzer commented Jan 4, 2018

I am just reusing the same strategy as for paths, which are also not drawn at all.

@anntzer anntzer force-pushed the ps-fully-transparent-text branch from 0491b56 to 6443aa9 Compare January 4, 2018 21:56
@afvincent
Copy link
Contributor

Fair enough then :).

@afvincent
Copy link
Contributor

Reading once more this line (and the next one...), I wonder if the special casing for text should not simply check if gc.get_rgb()[3] == 0.0 (fully transparent, any color) rather than gc.get_rgb() == (0, 0, 0, 0) (fully transparent, black).

PS doesn't really support transparency (because the format itself
doesn't, unless using some nonstandard extensions), but has some special
casing for "fully transparent" (see e.g. "rgbFace is None" check in
_draw_ps).

Also implement the special-casing for text.
@anntzer anntzer force-pushed the ps-fully-transparent-text branch from 6443aa9 to ee043fc Compare January 4, 2018 22:12
@anntzer
Copy link
Contributor Author

anntzer commented Jan 4, 2018

sounds good, improved test accordingly as well

Copy link
Contributor

@afvincent afvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :).

@tacaswell tacaswell added this to the v2.2 milestone Jan 5, 2018
@tacaswell
Copy link
Member

The added test files is a .pdf, that seems surprising to me...

@jklymak jklymak merged commit da9c7e4 into matplotlib:master Jan 6, 2018
@afvincent
Copy link
Contributor

Thx @anntzer and @jklymak !

@anntzer anntzer deleted the ps-fully-transparent-text branch January 6, 2018 00:47
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

savefig with eps draws a hidden axis
5 participants