python 子图的单独 X 和 Y 标签
python Individual X and Y Label for Subplot
我正在尝试为每个子图的 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' object has no attribute '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()
我正在尝试为每个子图的 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' object has no attribute '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()