title: Multiple dot syntax in python and matplotlib
body: <p>I am just studying this matplotlib example <a href="https://stackoverflow.com/a/21688791/406686">https://stackoverflow.com/a/21688791/406686</a> but don't understand the dot syntax.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import matplotlib.patches as patches
  class DraggablePoint:
      lock = None #only one can be animated at a time
      def __init__(self, point):
          self.point = point
          self.press = None
          self.background = None
  
      def connect(self):
          'connect to all the events we need'
          self.cidpress = self.point.figure.canvas.mpl_connect('button_press_event', self.on_press)
          self.cidrelease = self.point.figure.canvas.mpl_connect('button_release_event', self.on_release)
          self.cidmotion = self.point.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
  
      def on_press(self, event):
          if event.inaxes != self.point.axes: return
          if DraggablePoint.lock is not None: return
          contains, attrd = self.point.contains(event)
          if not contains: return
          self.press = (self.point.center), event.xdata, event.ydata
          DraggablePoint.lock = self
  
          # draw everything but the selected rectangle and store the pixel buffer
          canvas = self.point.figure.canvas
          axes = self.point.axes
          self.point.set_animated(True)
          canvas.draw()
          self.background = canvas.copy_from_bbox(self.point.axes.bbox)
  
          # now redraw just the rectangle
          axes.draw_artist(self.point)
  
          # and blit just the redrawn area
          canvas.blit(axes.bbox)
  
      def on_motion(self, event):
          if DraggablePoint.lock is not self:
              return
          if event.inaxes != self.point.axes: return
          self.point.center, xpress, ypress = self.press
          dx = event.xdata - xpress
          dy = event.ydata - ypress
          self.point.center = (self.point.center[0]+dx, self.point.center[1]+dy)
  
          canvas = self.point.figure.canvas
          axes = self.point.axes
          # restore the background region
          canvas.restore_region(self.background)
  
          # redraw just the current rectangle
          axes.draw_artist(self.point)
  
          # blit just the redrawn area
          canvas.blit(axes.bbox)
  
      def on_release(self, event):
          'on release we reset the press data'
          if DraggablePoint.lock is not self:
              return
  
          self.press = None
          DraggablePoint.lock = None
  
          # turn off the rect animation property and reset the background
          self.point.set_animated(False)
          self.background = None
  
          # redraw the full figure
          self.point.figure.canvas.draw()
  
      def disconnect(self):
          'disconnect all the stored connection ids'
          self.point.figure.canvas.mpl_disconnect(self.cidpress)
          self.point.figure.canvas.mpl_disconnect(self.cidrelease)
          self.point.figure.canvas.mpl_disconnect(self.cidmotion)
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  drs = []
  circles = [patches.Circle((0.32, 0.3), 0.03, fc='r', alpha=0.5),
                 patches.Circle((0.3,0.3), 0.03, fc='g', alpha=0.5)]
  
  for circ in circles:
      ax.add_patch(circ)
      dr = DraggablePoint(circ)
      dr.connect()
      drs.append(dr)
  
  plt.show()
  </code></pre>
  
  <p>Now take for example the line</p>
  
  <p><code>ax.add_patch(circ)</code></p>
  
  <p>This seems to be pretty clear to me. The <code>axes</code> class has a method called <code>add_patch</code> which takes (in particular) <code>Circle</code> objects as argument. So <code>ax.add_patch(circ)</code> just calls this method from the object <code>ax</code> which is an <code>axes</code> instance. </p>
  
  <p>The dot in <code>import matplotlib.patches</code> seems to have a different meaning. It just accesses the module <code>patches</code> which is a submodule of <code>matplotlib</code> see <a href="http://matplotlib.org/1.3.1/py-modindex.html" rel="nofollow noreferrer">http://matplotlib.org/1.3.1/py-modindex.html</a> for a list of modules.</p>
  
  <p>And a module as I understand it is just a python file containing some classes and functions.</p>
  
  <p>Now consider:</p>
  
  <p><code>self.cidpress = self.point.figure.canvas.mpl_connect('button_press_event', self.on_press)</code></p>
  
  <p><code>self.point</code> is the <code>point</code> variable defined in init (which doesn't need to be a fixed type). Later in the code there are <code>DraggablePoint</code> objects instantiated via <code>dr = DraggablePoint(circ)</code> where <code>circ</code> is a <code>patches.Circle</code> object. Now I struggle to interpret <code>self.point.figure</code>. The <code>figure</code> in this case cannot be a function since there is no <code>()</code> at the end. For me it also doen't make sense to see it as module in this case. I guess it is a type of shorthand for somehing like <code>self.point.get_current_figure()</code> which returns the figure where the point is drawn on. Similarly the <code>self.point.figure.canvas</code> seems to be something like <code>self.point.get_current_figure().get_canvas()</code> which returns the current canvas. However there seems to be no <code>get_current_figure</code> or <code>get_canvas</code> methods in the <code>mathplotlib.patches.Circ</code> class resp. the <code>mathmatplotlib.figure.Figure</code> class (see: 
  <a href="http://matplotlib.org/1.3.1/api/artist_api.html#module-matplotlib.patches" rel="nofollow noreferrer">http://matplotlib.org/1.3.1/api/artist_api.html#module-matplotlib.patches</a> and <a href="http://matplotlib.org/1.3.1/api/figure_api.html#matplotlib.figure.Figure" rel="nofollow noreferrer">http://matplotlib.org/1.3.1/api/figure_api.html#matplotlib.figure.Figure</a>). </p>
  
  <p>So it would be great if someone could clarify this for me. And more generally:</p>
  
  <ul>
  <li><p>There seems to be multiple different meanings of dot notation in python. Which are there, how are they called and how do I know which one is used?</p></li>
  <li><p>How can I see that I can call <code>self.point.figure</code> or <code>self.point.figure.canvas</code> from the matplotlib api docs? As noted above I didn't find it in the docs.</p></li>
  </ul>