How to switch axes in matplotlib?

前端 未结 2 855
再見小時候
再見小時候 2021-01-17 07:58

I like to switch x axis with y axis after plotting a graph with matplotlib? Any easy way for it? Thanks in advance.

2条回答
  •  [愿得一人]
    2021-01-17 08:04

    You can simply switch x and y parameters in the plot function:

    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)
    

提交回复
热议问题