Plotting Shapes In Matplotlib Through A Loop
plotting beginner here... I'm trying to get Matplotlib to add circles to a figure in a loop such that it runs 'N' times. N is given by user input and for my application likely won'
Solution 1:
The pseudocode is already quite good. There is no need for a list. Just loop up till N
and each time add the circle to the axes.
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6,2))
ax.set_aspect("equal")
N = 10
circle_list = []
circle = []
circle_size = np.random.rand(N)/5.+0.1
circle_x = np.arange(N)+1
for i in range(N):
c = plt.Circle((circle_x[i],0), circle_size[i])
ax.add_artist(c)
plt.xlim([0,N+1])
plt.ylim([-1,1])
plt.savefig(__file__+".png")
plt.show()
Post a Comment for "Plotting Shapes In Matplotlib Through A Loop"