在 matplotlib 中,当标签旋转、移动到右侧和顶部时,如何使 y 标签与图的顶部对齐?
import matplotlib.pyplot as plt
import numpy as np
#create plot
fig, ax = plt.subplots()
ax.plot(np.sin(np.linspace(-np.pi, np.pi, 1001)))
ax.tick_params(
which="both",
direction="out",
left=False,
right=True,
labelleft=False,
labelright=True,
)
ax.set_ylabel("y-label", loc="top", rotation=-90, labelpad=10)
ax.yaxis.set_label_position("right")