Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
matplotlib/lib/matplotlib/axes/_base.py
Lines 2054 to 2058 in5a10e4d
ifshared_xandshared_y: | |
raiseRuntimeError("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 changed this part as below, it worked like a charm as I expected.
ifshared_xandshared_y:return
Code for reproduction
#!/usr/bin/env pythonfrommatplotlibimportpyplotaspltfig,ax=plt.subplots(2,1,sharex=True,sharey=True)# Case 1ax[0].plot(range(0,3),range(3,6))ax[1].plot(range(10,13),range(0,3))# Case 2# ax[0].plot(range(3,6), range(0,3))# ax[1].plot(range(0,3), range(10,13))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
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
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