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

Skip to content

[ENH]: Switch text wrapping boundary to subfigure #28378

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
2 tasks
timhoffm opened this issue Jun 12, 2024 · 5 comments · Fixed by #28401
Closed
2 tasks

[ENH]: Switch text wrapping boundary to subfigure #28378

timhoffm opened this issue Jun 12, 2024 · 5 comments · Fixed by #28401
Milestone

Comments

@timhoffm
Copy link
Member

Problem

xref #28358 (comment)

Proposed solution

When #28177 is in, we could switch the wrapping box to subfigure.

Actions:

  • change the get_figure() call in Text._get_wrap_line_width
  • update Text.set_wrap documentation to explicitly mention subfigure.
@rcomer
Copy link
Member

rcomer commented Jun 12, 2024

I'm confused why this doesn't already work, since Text.get_figure() currently returns the parent figure rather than the root.

In [11]: fig = plt.figure()

In [12]: sfig = fig.subfigures()

In [13]: ax = sfig.subplots()

In [14]: txt = ax.text(0, 0, "foo")

In [15]: txt
Out[15]: Text(0, 0, 'foo')

In [16]: txt.get_figure()
Out[16]: <matplotlib.figure.SubFigure at 0x7f2eff1b6ed0>

@rcomer
Copy link
Member

rcomer commented Jun 12, 2024

Should figure_box be involved in this line?

h2 = x0 / math.cos(math.radians(90 - quad))

Edit: and some of the lines above it. I guess when this was written figure_box.x0 and figure_box.y0 were always zero so didn't need accounting for.

@timhoffm
Copy link
Member Author

I'm confused why this doesn't already work

I have just checked that the code in #28358 (comment) does not wrap - assuming it was due to the root figure, but it may well be that there is a calculation issue instead.

@rcomer
Copy link
Member

rcomer commented Jun 12, 2024

Titles do not have a wrapping problem... 😕

fig = plt.figure()
sfig1, sfig2 = fig.subfigures(ncols=2)
ax1, ax2 = sfig2.subplots(nrows=2)
ax2.set_title("Another title that won't fit in this amount of space", wrap=True)
sfig2.suptitle("Long title that won't fit in this amount of space", wrap=True)
plt.show()

image

@tacaswell
Copy link
Member

I can confirm both that tick labels wrap incorrectly and titles wrap correctly and that the tick labels have the correct (sub) figure attached to them.

Very odd.

@tacaswell tacaswell added this to the v3.10.0 milestone Jun 14, 2024
timhoffm added a commit to timhoffm/matplotlib that referenced this issue Jun 15, 2024
`_get_dist_to_box()` assumed that the figure box (x0, y0) coordinates
are 0, which was correct at the time of writing, but does not hold
anymore since the introduction of subfigures.

Closes matplotlib#28378
Closes matplotlib#28358
timhoffm added a commit to timhoffm/matplotlib that referenced this issue Jun 15, 2024
`_get_dist_to_box()` assumed that the figure box (x0, y0) coordinates
are 0, which was correct at the time of writing, but does not hold
anymore since the introduction of subfigures.

Closes matplotlib#28378
Closes matplotlib#28358
@QuLogic QuLogic modified the milestones: v3.10.0, v3.9.1 Jun 19, 2024
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.

4 participants