简体   繁体   English

Matplotlib中圆形补丁的中心

[英]Center of a circle patch in Matplotlib

I have created an array of Circle patches in Matplotlib. 我在Matplotlib中创建了一个Circle补丁数组。 I need to get a list of the centers of these circle patches, for some computation. 我需要获取这些圆形斑块的中心的列表,以便进行一些计算。

On the documentation page of the circle patch (see matplotlib.patches.Circle on this page) , there don't seem to be any methods for extracting the center of the circle say as in mycircle.get_center . 在圆补丁(见matplotlib.patches.Circle上的文档页面页),也似乎并没有被用于提取圆心任何方法说在mycircle.get_center They have one for the radius, but not for the center. 他们有一个半径,但没有中心。 Any suggestions? 有什么建议么?

EDIT: 编辑:

Here is some code. 这是一些代码。 Basically, what I want to do is to create an interactive app in which the user clicks some disks with the mouse onto the screen. 基本上,我想做的是创建一个交互式应用程序,其中用户用鼠标在屏幕上单击一些磁盘。 The only constraint on positioning these disks, is that they should all be disjoint. 放置这些磁盘的唯一限制是所有磁盘均应不相交。 So when the user tries to insert a disk with a mouse click, I want to check if the new disk intersects the already inputted disks. 因此,当用户尝试用鼠标单击插入磁盘时,我想检查新磁盘是否与已输入的磁盘相交。

I am storing all the circle patches in an array called disk_arrangement . 我将所有圆形补丁存储在名为disk_arrangement的数组中。 Sure, I could create a separate array recording the centers, to do my job, but that seems ugly. 当然,我可以创建一个单独的数组来记录中心,以完成我的工作,但这看起来很丑。 That's why I hope Matplotlib as a method to extract the center of a given circle-patch 这就是为什么我希望Matplotlib作为一种提取给定圆斑的中心的方法

def place_disk(event, disk_arrangement=[] ):

    def is_inside_an_existing_disk(center_x, center_y):
      if disk_arrangement != []:
        for existing_disk in disk_arrangement:
            if existing_disk.contains(event): #### How to do this????
               return True 
      return False

    if event.name     == 'button_press_event' and \
       event.dblclick == True                 and \
       event.xdata    != None                 and \
       event.ydata    != None                 and \
       is_inside_an_existing_disk(event.xdata,event.ydata) == False :  
              cursor_circle = mpl.patches.Circle((event.xdata,
                                                  event.ydata),
                                                  radius=0.3,
                                                  facecolor= 'green')
              disk_arrangement.append(cursor_circle)
              ax.add_patch(cursor_circle)
              fig.canvas.draw()

I am using Python 2.7.11 on Ubuntu 14.04 我在Ubuntu 14.04上使用Python 2.7.11

Try the center attribute, eg for a patch initialized with: 尝试center属性,例如,使用以下命令初始化的补丁:

from matplotlib.patches import Circle    
circ = Circle((1, 2), radius=1)
circ.center == (1,2) #should return True

To determine all the attributes of an object you can use dir , eg dir(circ) gives all attributes of the circ object including center , radius , etc. 要确定对象的所有属性,可以使用dir ,例如dir(circ)给出circ对象的所有属性,包括centerradius等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM