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

Skip to content

[Bug]: Cannot share both axis when setting aspect ratio #30203

Open
@ssrokyz

Description

@ssrokyz

Bug summary

if shared_x and shared_y:
raise RuntimeError("set_aspect(..., adjustable='datalim') or "
"axis('equal') are not allowed when both axes "
"are shared. Try set_aspect(..., "
"adjustable='box').")

This part is a strong regulation.
People would like to share both x and y axes when setting the aspect ratio to a certain value.
Though there will be a conflict in datalim between subplots, it is a minor problem to me.

When I removed this part, it worked like a charm as I expected.

Code for reproduction

#!/usr/bin/env python
from matplotlib import pyplot as plt

fig, ax = plt.subplots(2,1, sharex=True, sharey=True)

ax[0].plot(range(0,3), range(0,3))
ax[1].plot(range(3,7), range(3,7))

ax[0].set_box_aspect(1)
ax[1].set_box_aspect(1)
ax[1].set_aspect('equal', adjustable='datalim', share=True)

plt.show()

Actual outcome

Traceback (most recent call last):
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_qt.py", line 508, in _draw_idle
self.draw()
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_agg.py", line 382, in draw
self.figure.draw(self.renderer)
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/artist.py", line 94, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/artist.py", line 71, in draw_wrapper
return draw(artist, renderer)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/figure.py", line 3246, in draw
artists = self._get_draw_artists(renderer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/figure.py", line 166, in _get_draw_artists
ax.apply_aspect(locator(ax, renderer) if locator else None)
File "/home/ssrokyz/app/miniforge3/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 2061, in apply_aspect
raise RuntimeError("set_aspect(..., adjustable='datalim') or "
RuntimeError: set_aspect(..., adjustable='datalim') or axis('equal') are not allowed when both axes are shared. Try set_aspect(..., adjustable='box').

Expected outcome

Image

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.1

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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions