Half or quarter polar plots in Matplotlib?

前端 未结 2 1964
醉话见心
醉话见心 2020-12-30 02:35

I am trying to make a polar plot that goes 180 degrees instead of 360 in Matplotlib similar to http://www.mathworks.com/matlabcentral/fileexchange/27230-half-polar-coordinat

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 03:12

    The following works in matplotlib 2.1 or higher. There is also an example on the matplotlib page.
    You may use a usual polar plot, ax = fig.add_subplot(111, polar=True) and confine the theta range. For a half polar plot

    ax.set_thetamin(0)
    ax.set_thetamax(180)
    

    or for a quarter polar plot

    ax.set_thetamin(0)
    ax.set_thetamax(90)
    

    Complete example:

    import matplotlib.pyplot as plt
    import numpy as np
    
    theta = np.linspace(0,np.pi)
    r = np.sin(theta)
    
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=True)
    c = ax.scatter(theta, r, c=r, s=10, cmap='hsv', alpha=0.75)
    
    ax.set_thetamin(0)
    ax.set_thetamax(180)
    
    plt.show()
    

提交回复
热议问题