簡體   English   中英

如何在matplotlib中切換軸?

[英]How to switch axes in matplotlib?

在使用matplotlib繪制圖形后,我喜歡用y軸切換x軸嗎? 有什么簡單的方法嗎? 提前致謝。

我想如果你真的想要改變現有情節的數據,這將是一種方法:

首先執行此代碼以獲得數字:

# 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])

然后使用它來切換現有行的數據

# 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)

您只需在繪圖功能中切換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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM