Skip to content
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

[Doc]: Garbled menu widget example output #27358

Closed
StefRe opened this issue Nov 21, 2023 · 8 comments · Fixed by #27365
Closed

[Doc]: Garbled menu widget example output #27358

StefRe opened this issue Nov 21, 2023 · 8 comments · Fixed by #27365
Labels
Documentation: examples files in galleries/examples
Milestone

Comments

@StefRe
Copy link
Contributor

StefRe commented Nov 21, 2023

Documentation Link

https://matplotlib.org/devdocs/gallery/widgets/menu.html

Problem

grafik

Suggested improvement

Should be as in version 3.4 and before:
grafik

@ksunden
Copy link
Member

ksunden commented Nov 21, 2023

This does not show up poorly when I run it locally, so not totally sure why it is going wrong on the docs...

@StefRe
Copy link
Contributor Author

StefRe commented Nov 21, 2023

Right: sphx_glr_menu_001.png is correct and only sphx_glr_menu_001_2_00x.png is poorly aligned.
So the issue is linked to saving the figure with dpi settings different from 100, probably caused by using the IdentityTransform to specify label positions.

@ksunden
Copy link
Member

ksunden commented Nov 21, 2023

Ah... this is likely because the position, sizing, and padding values are specified in pixels in these examples, and not updated when the DPI changes... I know @QuLogic has had some thoughts towards similar problems in the past, so I will tag him in here.

@anntzer
Copy link
Contributor

anntzer commented Nov 22, 2023

I suspect the "easy" fix would be to reuse the trick of https://matplotlib.org/devdocs/gallery/text_labels_and_annotations/rainbow_text.html to position texts relative to one another.

@StefRe StefRe mentioned this issue Nov 23, 2023
2 tasks
@StefRe
Copy link
Contributor Author

StefRe commented Nov 23, 2023

I suspect the "easy" fix would be to reuse the trick of https://matplotlib.org/devdocs/gallery/text_labels_and_annotations/rainbow_text.html to position texts relative to one another.

While this solves the alignement issue I couldn't find a way to set all the text boxes to the same length without using get_window_extent. That's why I thought it would be easiest to just fake the output, see #27365.

@anntzer
Copy link
Contributor

anntzer commented Nov 23, 2023

I guess I could imagine ways to fix that with custom Annotation subclasses that override get_window_extent, but I agree it's probably not really worth the complexity.

@jklymak
Copy link
Member

jklymak commented Nov 23, 2023

The bbox could be converted to physical units and then all placement done in inches (or points) instead of pixels.

self.text_bbox = self.label.get_window_extent(
            fig.canvas.get_renderer())
self.text_bbox = fig.dpi_scale_trans.inverted().transform_bbox(self.text_bbox)

should be in inches. Then place things using fig.dpi_scale_trans rather than native pixels.

@StefRe
Copy link
Contributor Author

StefRe commented Nov 23, 2023

Thanks @jklymak, will update the PR.

@QuLogic QuLogic added Documentation: examples files in galleries/examples and removed Documentation labels Nov 24, 2023
@QuLogic QuLogic added this to the v3.8.3 milestone Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants