Half or quarter polar plots in Matplotlib?

前端 未结 2 1952
醉话见心
醉话见心 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条回答
  • 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()
    

    0 讨论(0)
  • 2020-12-30 03:12

    The example code in official matplotlib documentation may obscure things a little bit if someone just needs a simple quarter of half plot. I wrote a code snippet that may help someone who is not that familiar with AxisArtists here.

    The output image of this code snippet

    0 讨论(0)
提交回复
热议问题