skip to Main Content
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(13, 13))
ax1 = plt.subplot( projection='polar') 
ax1.set_theta_zero_location('N') 
ax1.set_thetagrids(np.arange(0.0, 360.0, 25.7143))# /14
ax1.set_rgrids(np.arange(0.8,1,))


amount1 = [('89','c'),'04','76',('93','a'),'56',
          '11','45','61','85',('37','b'),
          '51','97','24','07']
r = 0.8
#theta = 25.7143 * range(14) # amount1:add to intersections


plt.show()

enter image description here

chart make in photoshop.
I am a newbie with python.
I am a foreigner, and my question is expressed through code and graphics

2

Answers


  1. Include a color for all of the labels.

    amount1 = [('89','g'),('04','k'),('76','k'),('93','r'),('56','k'),
              ('11','k'),('45','k'),('61','k'),('85','k'),('37','b'),
              ('51','k'),('97','k'),('24','k'),('07','k')]
    

    You can specify the text coordinates in (theta, r) coordinates. The angle should be in radians

    theta = 2*pi/14
    for i in range(14):
        ax1.text(theta*i,0.8,amount1[i][0],color=amount[i][1],fontsize=24)
    
    Login or Signup to reply.
  2. To calculate the angles for set_thetagrids, you can use np.linspace from 0 to 360 with 14 steps but with endpoint=False.

    The angles for the placement are in radians; np.radians(thetas) converts them. To place the texts, you can loop through amount1. A little circle can be positioned e.g. via ax1.scatter(x, y, ...) with a given interior and edge color.

    import matplotlib.pyplot as plt
    import numpy as np
    
    fig = plt.figure(figsize=(13, 13))
    ax1 = plt.subplot(projection='polar')
    ax1.set_theta_zero_location('N')
    thetas = np.linspace(0, 360, 14, endpoint=False)
    ax1.set_thetagrids(thetas)
    ax1.set_rgrids([0.8, 1], [])
    ax1.set_ylim(0, 1)
    
    amount1 = [('89', 'c'), '04', '76', ('93', 'a'), '56', '11', '45', '61', '85', ('37', 'b'), '51', '97', '24', '07']
    r = 0.8
    for am1, theta in zip(amount1, np.radians(thetas)):
        color = 'white'
        if type(am1) is tuple:
            color = {'a': 'turquoise', 'b': 'orchid', 'c': 'lightcoral'}[am1[1]]
            am1 = am1[0]
        ax1.text(theta, r, am1, color='firebrick', ha='center', va='center')
        ax1.scatter(theta, r, s=500, marker='o', color=color, edgecolor='red', alpha=0.5)
    plt.show()
    

    polar plot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search