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

Skip to content

Set transform for offset text in 3d #26185

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

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

Rylie-W
Copy link

@Rylie-W Rylie-W commented Jun 25, 2023

PR summary

The PR set the transform for the offset text in 3d and add a unit test for the positioning of labels, offsets and ticks.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@oscargus
Copy link
Member

Nice!

Since this was basically broken earlier (for a while at least), I'm wondering if one should also adjust the behavior? To me, it seems like the text should maybe not be rotated?

A minor thing is that the z-label offset text doesn't look aligned with the label? Maybe there is some inconsistency in rotation anchor? (Which is then primarily a problem if the text is actually rotated, so we should probably decide which is the preferred approach first...)

Sorry about the additional questions. This clearly fixes a long standing issue, but since we more or less promise that it will be like this from now on, it is important to get it correct.

@Rylie-W
Copy link
Author

Rylie-W commented Jun 25, 2023

Hi @oscargus, thanks for the advice!

Regarding text rotation, the labels and offset text of each axis should align with the direction of the tick labels, instead of the X axis label rotating counterclockwise when the box rotates to the right as shown in the figure , is that correct?

For the second question, if Text.set_position() is used to set the the position of the anchor point, we can find the Z axis offset text is aligned with its label, with the label positioned at the center of the edge points and the offset text positioned next to an edge point from the following code:

  • calculation of the anchor point for the label

    lxyz = 0.5 * (edgep1 + edgep2)
    # A rough estimate; points are ambiguous since 3D plots rotate
    reltoinches = self.figure.dpi_scale_trans.inverted()
    ax_inches = reltoinches.transform(self.axes.bbox.size)
    ax_points_estimate = sum(72. * ax_inches)
    deltas_per_point = 48 / ax_points_estimate
    default_offset = 21.
    labeldeltas = (
    (self.labelpad + default_offset) * deltas_per_point * deltas)
    axmask = [True, True, True]
    axmask[index] = False
    lxyz = _move_from_center(lxyz, centers, labeldeltas, axmask)
    tlx, tly, tlz = proj3d.proj_transform(*lxyz, self.axes.M)
    self.label.set_position((tlx, tly))

  • calculation of the anchor point for the offset text

    # Which of the two edge points do we want to
    # use for locating the offset text?
    if juggled[2] == 2:
    outeredgep = edgep1
    outerindex = 0
    else:
    outeredgep = edgep2
    outerindex = 1
    pos = _move_from_center(outeredgep, centers, labeldeltas, axmask)
    olx, oly, olz = proj3d.proj_transform(*pos, self.axes.M)
    self.offsetText.set_text(self.major.formatter.get_offset())
    self.offsetText.set_position((olx, oly))

@oscargus
Copy link
Member

I think that we can define ourselves what is correct since it has been broken for so long(?). So it probably a matter of opinion.

Looking at the animation it is not so clear what is the preferred behavior. I think that looks quite good with the current approach. The z-alignment issue doesn't seem like a problem in the animation either. I wonder if there is some drawing order problem so that it happens for a single image, but not for an animation?

@scottshambaugh any opinions as one of the persons working on the 3D stuff?

If nothing else, I'll try to clarify this on the dev-call on Thursday and then we hopefully can reach an agreement what the expected behavior is. (Feel free to join if you want to. Info on https://hackmd.io/Ya6IQSTjSBqJ7TCY6MxUQQ )

@CarrascoCesar
Copy link

I implemented the update created by Rylie-W and can confirm that it solves the problem in the code I uploaded and also in the application I am developing. Thanks for the great work Rylie!!

@oscargus oscargus added this to the v3.8.0 milestone Jun 26, 2023
@WeatherGod
Copy link
Member

WeatherGod commented Jun 28, 2023 via email

@tacaswell
Copy link
Member

@tacaswell
Copy link
Member

Discussed on call. The orientation of the offset texts is a long standing feature so lets take the bug-fix of getting them visible and defer discussion of if the orientation should be changed or not to a later date.

@Rylie-W Rylie-W force-pushed the fix-offset-positioning branch from 334f1fd to 8953596 Compare June 29, 2023 22:01
@ksunden ksunden merged commit 3b3fc57 into matplotlib:main Jun 29, 2023
@ksunden
Copy link
Member

ksunden commented Jun 29, 2023

Congrats @Rylie-W on your first merged PR, hope to hear from you again!

@QuLogic QuLogic removed the status: needs comment/discussion needs consensus on next step label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[Bug]: Axis multiplier when using plot_surface appears outside of the figure window
7 participants