首页 > 解决方案 > 源代码的圆类中用于半径的测量单位是什么:matplotlib.patches

问题描述

查看源代码中的圆类:https ://matplotlib.org/3.1.1/_modules/matplotlib/patches.html#Circle.set_radius

我试图确定半径是英里、米还是公里。我如何检查它。

圆圈已经画好了,我试着手动估计看圆圈,但不认为这是一个很好的验证方式

class Circle(Ellipse):
    """
    A circle patch.
    """
    def __str__(self):
        pars = self.center[0], self.center[1], self.radius
        fmt = "Circle(xy=(%g, %g), radius=%g)"
        return fmt % pars

    @docstring.dedent_interpd
    def __init__(self, xy, radius=5, **kwargs):
        """
        Create true circle at center *xy* = (*x*, *y*) with given
        *radius*.  Unlike :class:`~matplotlib.patches.CirclePolygon`
        which is a polygonal approximation, this uses Bezier splines
        and is much closer to a scale-free circle.

        Valid kwargs are:
        %(Patch)s

        """
        Ellipse.__init__(self, xy, radius * 2, radius * 2, **kwargs)
        self.radius = radius

[docs]    def set_radius(self, radius):
        """
        Set the radius of the circle

        Parameters
        ----------
        radius : float
        """
        self.width = self.height = 2 * radius
        self.stale = True


[docs]    def get_radius(self):
        """
        Return the radius of the circle
        """
        return self.width / 2.


    radius = property(get_radius, set_radius)

预期:半径应以英里为单位 实际:不清楚用于半径的测量单位

标签: pythonmatplotlib

解决方案


如果你塑造你的实现,比如从两点获得距离,它会给你两点之间的距离,在这里你可以选择半径。

import math
p1 = [-118.22191509999999, 34.0431494]
p2 = [-118.13458169630128, 34.04311852494086]
distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )
self.ax1.add_patch(Circle((-118.22191509999999, 34.0431494), 0.08733340915635142, fill=False))

0.08733340915635142 是您的距离和半径。


推荐阅读