2

I have created an array of Circle patches in Matplotlib. 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. 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. 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

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

2
  • Aren't you providing the coordinates of the center when defining the patches? A minimal working example would be useful Commented Mar 19, 2016 at 22:55
  • @nluigi See edit. Thanks! Commented Mar 19, 2016 at 23:05

1 Answer 1

3

Try the center attribute, e.g. for a patch initialized with:

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, e.g. dir(circ) gives all attributes of the circ object including center, radius, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.