Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]:ax.transData does not honor data limits #28075

Open
@ShawnZhong

Description

@ShawnZhong

Bug summary

ax.transData does not honorxlim andylim. The document athttps://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates seems to suggest that data limits are updated automatically when new data are added to the axes, but it's not the case, which breaksax.transData, since it reads an old version of data limits.

Code for reproduction

frommatplotlibimportpyplotaspltfig,ax=plt.subplots(figsize=(10,10),dpi=100)print(f"fig size:{fig.get_size_inches()*fig.dpi}")ax.plot([0,10], [0,10],'o')print(f"(10, 10) in data coordinates:{ax.transData.transform((10,10))}")ax.set_xlim(ax.get_xlim())# just ax.get_xlim() or ax.viewLim or ax.autoscale_view() is enoughax.set_ylim(ax.get_ylim())print(f"(10, 10) in data coordinates:{ax.transData.transform((10,10))}")

Actual outcome

fig size: [1000. 1000.]
(10, 10) in data coordinates: [7875. 7810.]
(10, 10) in data coordinates: [864.77272727 845. ]

Expected outcome

fig size: [1000. 1000.]
(10, 10) in data coordinates: [864.77272727 845. ]
(10, 10) in data coordinates: [864.77272727 845. ]

Additional information

The wording fromhttps://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates suggests that data limits are updated automatically when new data are added, but it requires manual trigger ofset_xlim/set_ylim (orget_xlim/get_ylim which callsax.viewLim).

This is quite confusing. I would hope that either the documentation is updated to notify the user to explicitly update the data limits, or even better, lettransData/transLimits always use the latest data limits.

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp