我想如果您真的想更改现有图的数据,这将是一种方法:
首先执行此代码以获取图形:
# generate a simple figure
f, ax = plt.subplots()
ax.plot([1,2,3,4,5], [5,6,7,8,9])
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
Run Code Online (Sandbox Code Playgroud)
然后使用它来切换现有行的数据
# get data from first line of the plot
newx = ax.lines[0].get_ydata()
newy = ax.lines[0].get_xdata()
# set new x- and y- data for the line
ax.lines[0].set_xdata(newx)
ax.lines[0].set_ydata(newy)
Run Code Online (Sandbox Code Playgroud)
您可以简单地在绘图函数中切换 x 和 y 参数:
I[3]: x = np.linspace(0,2*np.pi, 100)
I[4]: y = np.sin(x)
I[5]: plt.plot(x,y)
I[6]: plt.figure(); plt.plot(y,x)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14580 次 |
| 最近记录: |