Set radial axis on Matplotlib polar plots

后端 未结 1 1032
北荒
北荒 2021-01-12 19:28

I\'m plotting an azimuth-elevation curve on a polar plot where the elevation is the radial component. By default, Matplotlib plots the radial value from 0 in the center to 9

1条回答
  •  清酒与你
    2021-01-12 19:47

    I managed to put he radial axis inverted. I had to remap the radius, in order to match the new axis:

    fig = figure()
    ax = fig.add_subplot(1, 1, 1, polar=True)
    
    def mapr(r):
       """Remap the radial axis."""
       return 90 - r
    
    r = np.arange(0, 90, 0.01)
    theta = 2 * np.pi * r / 90
    
    ax.plot(theta, mapr(r))
    ax.set_yticks(range(0, 90, 10))                   # Define the yticks
    ax.set_yticklabels(map(str, range(90, 0, -10)))   # Change the labels
    

    Note that is just a hack, the axis is still with the 0 in the center and 90 in the perimeter. You will have to use the mapping function for all the variables that you are plotting.

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