caliGeek
caliGeek

Reputation: 419

Detect distance of measurement used for radius while drawing circle in python

I have a code in Python which creates a circle. However I am unsure about the distance of measurement used while drawing the circle. Can someone please recommend how to check that.

Tried changing the radius to value of 5000 to see if the size of the circle changes. No changes reflected.

import matplotlib.pyplot as plt 
from matplotlib.patches import Circle
from descartes import PolygonPatch

    BLUE = '#6699cc'
    fig = plt.figure() 
    ax = fig.gca() 
    ax.add_patch(Circle((-118.22191509999999, 34.0431494), 5, fill = False ))
    ax.axis('scaled')
    plt.show()

Expected the circle to be bigger when 5000 was used as radius. Unsure whether the radius is in miles or meters or km.

Upvotes: 0

Views: 283

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40737

Unless otherwise specified with transform= the radius is expressed in data units. Therefore a circle with radius 5000 is 1000x larger than a circle with radius 5. If you do not draw anything else on the axes, the range of the axes will be adjusted automatically and therefore the visual aspect of the circles will not differ. However, if you look at the x/y tick labels, you can clearly see that one is bigger that the other.

import matplotlib.pyplot as plt 
from matplotlib.patches import Circle

fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(15,5))
ax1.add_patch(Circle((-118.22191509999999, 34.0431494), 5, fill=False))
ax2.add_patch(Circle((-118.22191509999999, 34.0431494), 5000, fill=False))
c1 = Circle((-118.22191509999999, 34.0431494), 5, fill=False, ec='b')
c2 = Circle((-118.22191509999999, 34.0431494), 10, fill=False, ec='r')
ax3.add_patch(c1)
ax3.add_patch(c2)
ax3.legend([c1,c2],['radius=5', 'radius=10'])
for ax in [ax1, ax2, ax3]:
    ax.axis('scaled')
ax2.set_title("Notice the different data range")
plt.show()

enter image description here

Upvotes: 0

Related Questions