|

Python 3.11.6 (matplotlib 3.7.1) では、正常実行です。
Python 3.12.0 (matplotlib 3.8.1) では、下記のような警告があるが、実行できる。
E:\______\spines_demo_bounds.py:19: SyntaxWarning: invalid escape sequence '\p'
ax.set_xticklabels(['0', '$\pi$', '2$\pi$'])
escape sequence '$\pi$' を '\u03c0' に、書き換えてみました。
"""
Demo of spines using custom bounds to limit the extent of the spine.
"""
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)
y2 = y + 0.1 * np.random.normal(size=x.shape)
fig, ax = plt.subplots()
ax.plot(x, y, 'k--')
ax.plot(x, y2, 'ro')
# set ticks and tick labels
ax.set_xlim((0, 2*np.pi))
ax.set_xticks([0, np.pi, 2*np.pi])
# ax.set_xticklabels(['0', '$\pi$', '2$\pi$'])
ax.set_xticklabels(['0', '\u03c0', '2\u03c0'])
ax.set_ylim((-1.5, 1.5))
ax.set_yticks([-1, 0, 1])
# Only draw spine between the y-ticks
ax.spines['left'].set_bounds(-1, 1)
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Only show ticks on the left and bottom spines
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
plt.show()
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) 共に、正常実行です。

|