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]: Modifying Axes' position also alters the original Bbox object used for initialization #29410

Milestone
@hu-xiaonan

Description

@hu-xiaonan

Bug summary

When an Axes is initialized using a Bbox object, changing the Axes' position (for example, viaax.set_position) will also alter the original Bbox object. This is because the Axes retains a reference to the Bbox object rather than creating a separate copy during initialization.

Code for reproduction

importmatplotlib.pyplotaspltfrommatplotlib.transformsimportBboxbbox=Bbox([[0.1,0.1], [0.9,0.9]])fig=plt.figure()ax=fig.add_axes(bbox)ax.set_position([0.25,0.25,0.5,0.5])print(bbox)print(id(bbox),id(ax._position))

Actual outcome

Bbox(x0=0.25, y0=0.25, x1=0.75, y1=0.75)
140507022809120 140507022809120

Expected outcome

Bbox(x0=0.1, y0=0.1, x1=0.9, y1=0.9)
... ... # Two different IDs

Additional information

This issue originates from_AxesBase.__init__,

iflen(args)==1andisinstance(args[0],mtransforms.Bbox):
self._position=args[0]

whereargs[0] is directly assigned toself._position without making a copy.

I don't know if this is a bug or a feature, but it does break encapsulation.

Additionally, some other initialization methods (for example,Bbox.__init__) that usenp.asarray instead ofnp.array can cause similar issues.

Operating system

No response

Matplotlib Version

3.10.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp