python子图的单独X和Y标签

我正在尝试为每个子图的x和y轴设置单独的标签。我尝试了以下方法:

# First create some toy data:
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)

# Creates just a figure and only one subplot
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')

ax.set_xlabel('X')
ax.set_ydata("Y")

...但是我得到:

AttributeError:“ AxesSubplot”对象没有属性“ set_xdata”

知道我在做什么错吗?

评论
  • 喂圆圆
    喂圆圆 回复

    If you are trying to set the X and Y labels, you should useax.set_ylabel('Y') rather than ax.set_ydata("Y").

  • 不No
    不No 回复

    You wrote ax.set_ydata instead of ax.set_ylabel