Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Doc]: Incorrectly drawn bounding box #26264

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

Closed
tacaswell opened this issue Jul 5, 2023 · 3 comments · Fixed by #26265
Closed

[Doc]: Incorrectly drawn bounding box #26264

tacaswell opened this issue Jul 5, 2023 · 3 comments · Fixed by #26265
Milestone

Comments

@tacaswell
Copy link
Member

Documentation Link

https://matplotlib.org/devdocs/users/explain/figure/figure_intro.html#saving-figures

Problem

If you have a high-dpi screen (or download the 2x png) the dashed line is the wrong size and shape.

Suggested improvement

No response

@tacaswell tacaswell changed the title [Doc]: [Doc]: Incorrectly drawn bounding box Jul 5, 2023
@tacaswell
Copy link
Member Author

Thanks to @QuLogic I now have a plan to fix this.

@jklymak
Copy link
Member

jklymak commented Jul 5, 2023

Oh yeah, I noticed that the other day. It's a function of the 2x images not having the correct bounding box. The 1x is fine (and indeed any fix might break that ;-).

@tacaswell
Copy link
Member Author

import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch

fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue')
ax.set_position([0.1, 0.2, 0.8, 0.7])
ax.set_aspect(1)
bb = ax.get_tightbbox()
bb = bb.padded(10)
bb = bb.transformed(fig.dpi_scale_trans.inverted())
fancy = FancyBboxPatch(bb.p0, bb.width, bb.height, fc='none',
                       ec=(0, 0.0, 0, 0.5), lw=2, linestyle='--',
                       transform=fig.dpi_scale_trans,
                       clip_on=False, boxstyle='Square, pad=0')
ax.add_patch(fancy)

is the fix. Discovered that FancyBboxPatch pads its input a bit so took a bit of iteration to get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants