Skip to content

Fix hatch linewidth in PGF #24263

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oscargus
Copy link
Member

Co-authored-by: Antony Lee anntzer.lee@gmail.com

PR Summary

Closes #15491

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus oscargus marked this pull request as ready for review October 24, 2022 16:05
@oscargus
Copy link
Member Author

Not obvious why this kills all Linux tests, but no Windows or Mac tests.

@oscargus
Copy link
Member Author

This looks extremely fragile. After a rebase I get even more errors... Especially, it seems like the conversion from PDF to PNG is affected for some unknown reason.

An example:

Screenshot of expected PDF
image

Screenshot of resulting PDF
image

These look quite the same IMHO.

PNG of expected PDF
fancy-expected_pdf

PNG of resulting PDF
fancy_pdf

Expected PNG for reference
fancy-expected

@oscargus
Copy link
Member Author

oscargus commented Nov 3, 2022

I cannot run the whole test suite locally in one go as I get a Fatal Python error: Illegal instruction every now and then. Most tests that fails here pass locally though (some minor, single pixel type of errors).

However, I noted this error from the test log:

! Package geometry Error: \paperheight (0.72229pt) too short.

See the geometry package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.1006 \Gm@process
                  
No pages of output.
Transcript written on figure.log.

and the following error:

So it may indeed be related to what was discussed during the dev call: something messes up the ghostscript conversion process that propagates among the tests.

@oscargus oscargus marked this pull request as draft November 3, 2022 21:55
@tacaswell
Copy link
Member

Fatal Python error: Illegal instruction

Those tend to come from binaries compiled with CPU instruction sets that your CPU does not have...and I have mostly seen them with mkl or other "go fast" numpy extensionss....

@oscargus oscargus force-pushed the pgfhatchlinewidth branch 3 times, most recently from 1c7cd9f to 4b2dc96 Compare November 6, 2022 11:23
@oscargus oscargus mentioned this pull request Jan 24, 2025
2 tasks
@story645
Copy link
Member

Hi @oscargus any plans to finish this up? Particularly so that #29392 can get rebased on it?

@oscargus
Copy link
Member Author

I'd be happy to finish it. Just that I do not really know what remains to be done and/or what causes the weird inconsistent test images.

But I'll try to rebase it and see what the current status is and if anything has changed.

@pytest.mark.backend('pgf')
@image_comparison(['hatch_linewidth'], extensions=['pdf'])
def test_pgf_hatch_linewidth():
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
Copy link
Member

Choose a reason for hiding this comment

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

Considering how many things are failing, this must be a global setting that isn't reset.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, good observation! That is indeed a good first thing to fix. I'll give it a try.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure this works as expected (cannot run matplotlib from source locally for unknown reasons).

Main problem was how to change the backend back after the test. One may consider adding an argument to the image_comparison decorator that takes a lambda and evaluates it after the comparison is done.

I also considered using check_figure_equal and mocking two classes that has a save_fig method that sets backend, but didn't understand how to deal with the close call later on.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at it again, the tests in this file use pytest.mark.backend('pgf') with image_comparison(['foo.pdf']); do we really need the extra registration or are the other tests not working as expected?

@oscargus oscargus force-pushed the pgfhatchlinewidth branch 4 times, most recently from 3fa3d67 to d631b01 Compare June 4, 2025 09:00
@oscargus
Copy link
Member Author

oscargus commented Jun 4, 2025

I think the test is correct now.

Added a try-except block to make sure that the backend is always restored.

@oscargus oscargus force-pushed the pgfhatchlinewidth branch from d631b01 to 04232ab Compare June 4, 2025 09:22
@oscargus oscargus marked this pull request as ready for review June 4, 2025 10:04
@oscargus oscargus force-pushed the pgfhatchlinewidth branch from 04232ab to 44a728c Compare June 5, 2025 07:51
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
@oscargus oscargus force-pushed the pgfhatchlinewidth branch from 44a728c to 1d44eab Compare June 5, 2025 09:21
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.

Hatch line width ignored with pgf backend
4 participants