Skip to content

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

Closed

Description

@timhoffm

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.

Activity

  1. rcomer commented on Jun 12, 2024

    @rcomer
    Member

    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>
  2. rcomer commented on Jun 12, 2024

    @rcomer
    Member

    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.

  3. timhoffm commented on Jun 12, 2024

    @timhoffm
    MemberAuthor

    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.

  4. rcomer commented on Jun 12, 2024

    @rcomer
    Member

    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

  5. tacaswell commented on Jun 14, 2024

    @tacaswell
    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.

  6. added this to the v3.10.0 milestone on Jun 14, 2024
  7. added 3 commits that reference this issue on Jun 15, 2024
    29ef716
    2f10d3d
    cc85130
  8. modified the milestones: v3.10.0, v3.9.1 on Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions