rotate markers in a plot along an arc matplotlib

Viewed 30

I'm trying to plot the flag of Venezuela with matplotlib code using the code below:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patch

a = patch.Rectangle((0,1), width = 12, height = 2, facecolor = '#E41F26', edgecolor = 'grey')
b = patch.Rectangle((0,3), width = 12, height = 2, facecolor = '#253D99', edgecolor = 'grey')
c = patch.Rectangle((0,5), width = 12, height = 2, facecolor = '#FDCC02', edgecolor = 'grey')

m, n = plt.subplots()

n.add_patch(a)
n.add_patch(b)
n.add_patch(c)
plt.plot(6,4, markersize = 9.5)

x = np.linspace(3, 9, 8)
y = np.concatenate((np.linspace(3.5, 4.5, 4), np.linspace(4.5, 3.5, 4)))

for (p, q) in zip (x, y):
    n.plot(p, q, marker=(5, 1, q*10), color='white', markersize=35)

plt.show()

I would like to adjust the rotation of the stars as in the picture below about the Flag of venezuela

1 Answers

In your code, the stars are placed in a straight line because you are using an isometric sequence. So I created the xy coordinates to draw a circle and used the upper semicircle to place the stars. Also, the necessary number of stars are partially retrieved from the array and merged so that the vertices are zero at the angle of rotation. Please correct me if I am wrong.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patch

a = patch.Rectangle((0,1), width = 12, height = 2, facecolor = '#E41F26', edgecolor = 'grey')
b = patch.Rectangle((0,3), width = 12, height = 2, facecolor = '#253D99', edgecolor = 'grey')
c = patch.Rectangle((0,5), width = 12, height = 2, facecolor = '#FDCC02', edgecolor = 'grey')
fig, ax = plt.subplots()

ax.add_patch(a)
ax.add_patch(b)
ax.add_patch(c)

n = 23
center = (6,2)
radius = 2.5
theta = np.linspace(0, 2*np.pi, n)
x = center[0] + radius * np.cos(theta)
y = center[1] + radius * np.sin(theta)

rotate = np.arange(0,360,360/23)
rotate = np.append(rotate[:4][::-1], rotate[:4]*-1)

for (p, q, i) in zip(reversed(x[2:10]), reversed(y[2:10]), rotate):
    ax.plot(p, q, marker=(5, 1, i), color='white', markersize=15)

for pos in ['right','left','top','bottom']:
    ax.spines[pos].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
plt.show()

enter image description here

Related