|
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as axisartist
def setup_axes(fig, rect):
ax = axisartist.Subplot(fig, rect)
fig.add_subplot(ax)
ax.set_yticks([0.2, 0.8])
ax.set_xticks([0.2, 0.8])
return ax
fig = plt.figure(1, figsize=(5, 2))
fig.subplots_adjust(wspace=0.4, bottom=0.3)
ax1 = setup_axes(fig, "121")
ax1.set_xlabel("X-label")
ax1.set_ylabel("Y-label")
ax1.axis[:].invert_ticklabel_direction()
ax2 = setup_axes(fig, "122")
ax2.set_xlabel("X-label")
ax2.set_ylabel("Y-label")
ax2.axis[:].major_ticks.set_tick_out(True)
plt.show()

Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。
Traceback (most recent call last):
File "_:\Axis_Direction03_01.py", line 18, in
ax1 = setup_axes(fig, "121")
^^^^^^^^^^^^^^^^^^^^^^
File "_:\Axis_Direction03_01.py", line 6, in setup_axes
ax = axisartist.Subplot(fig, rect)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\mpl_toolkits\axisartist\axislines.py", line 444, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 641, in __init__
self._position = mtransforms.Bbox.from_bounds(*args[0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Bbox.from_bounds() missing 1 required positional argument: 'height'
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as axisartist
def setup_axes(fig, pos):
ax = fig.add_subplot(pos, axes_class=axisartist.Axes)
ax.set_yticks([0.2, 0.8])
ax.set_xticks([0.2, 0.8])
return ax
fig = plt.figure(figsize=(5, 2))
fig.subplots_adjust(wspace=0.4, bottom=0.3)
ax1 = setup_axes(fig, 121)
ax1.set_xlabel("X-label")
ax1.set_ylabel("Y-label")
ax1.axis[:].invert_ticklabel_direction()
ax2 = setup_axes(fig, 122)
ax2.set_xlabel("X-label")
ax2.set_ylabel("Y-label")
ax2.axis[:].major_ticks.set_tick_out(True)
plt.show()

|