我正在尝试为每个子图的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")
。但我得到:
属性错误:"轴子图"对象没有属性"set_xdata">
知道我做错了什么吗?
你写的是ax.set_ydata
而不是ax.set_ylabel
如果要尝试设置 X 和 Y 标签,则应使用ax.set_ylabel('Y')
而不是ax.set_ydata("Y")
。
我的英语不好,但是,你还好吗?
import numpy as np
import matplotlib.pyplot as plt
# 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')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()