Reputation: 10799
I would like to plot concentric circles at a given set of distances away from a source. The first thing I tried to do was draw an arc on polar plot, as this seemed like a logical substep:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot([1.0,1.5], [5,5], color='r', linestyle='-')
plt.show()
The first problem I'm having is that this draws a straight line rather than an arc:
So the subquestion might be how do I draw an arc, in this case a 360 degree arc, at a given radius on a polar plot?. On the other hand, there might be a better solution altogether, perhaps one that doesn't involve a polar plot. Ultimately, as per the title, my objective is to draw concentric circles at a set of radii around a centre source.
Upvotes: 3
Views: 7917
Reputation: 54340
easy, use it to make shooting targets all the time.:
ax.plot(np.linspace(0, 2*np.pi, 100), np.ones(100)*5, color='r', linestyle='-')
Just think of how you define a circle in a polar axis? Need two things, angle and radius. Those are np.linspace(0, 2*np.pi, 100)
and np.ones(100)*5
here. If you just need a arc, change the first argument to something less than 0 to 2pi. And change the 2nd argument accordingly.
There are other ways to do this.
plot()
creates .lines.Line2D object
objects, if you want .collections.PathCollection object
instead of Line2D:
ax.scatter(1, 0, s=100000, facecolors='none')
Or you want to make patch
es:
ax.bar(0, 5, 2*np.pi, bottom=0.0, facecolor='None') #need to modified the edge lines or won't look right
Upvotes: 5