Is the attached sort of what you want? It defines a custom rectangle by (x, w, y1, y2) and overrides the get_transform of the patch to update itself at draw time.

Mike

Uri Laserson wrote:
On Mon, Sep 28, 2009 at 16:03, Michael Droettboom <md...@stsci.edu> wrote:
If I understand correctly, the top and bottom of the box are in data
coordinates, the x-center of the box is in data coordinates, only the width
of the box is in axes coordinates.  Is that correct?  If so, a

That's exactly correct.

PolyCollection won't be able to do this (directly), since that would require
both the width and height to be in axes coordinates.

In principle, could you use a blended tranform for that?  Eitherway, I
don't think it would work, because the patch objects would be drawn to
specific Axes coords.  If the scale is changed (e.g, by switching to
log scale), then what would prompt the Axes coords to be recalculated?
 I was thinking earlier that I could compose the transData and
transAxes.inverse transforms to recalculate where the new Axes coord
should be, but Mike thought this approach would fail (though I'm still
not exactly sure why, no doubt because of my own ignorance).

Uri

Mike

Eric Firing wrote:
Uri Laserson wrote:

Is it possible to specify a path object that will use different
transforms for different vertices?

This is again related to plotting a box whose height is specified by
data coords, but whose width is a constant in axes coords regardless
of scale (so linear and log x-scales would produce a box of the same
width).

Ideally, I would draw a path like this:
1. the center of the box would be located at x and bottom and top
would be y1, y2, all in data coords
2. I would move to (x,y1) at the bottom-center of the box.
3. The x value would now need to be converted to Axes coords, possibly
by applying transData + transAxes.inverted
4. I would want to draw a line to (x-0.1, y1) where x is now in axes
coords and y is still in data coords.  Then up, then right, then down,
and then close the polygon.

How do I implement this?

I must be missing something, because I still don't see why you can't do
all this very simply by using a PolyCollection, with the vertices in axes
coordinates and the offset in data coordinates.

Eric


As I mentioned before, a blended transform would allow me to make the
moves i am interested in.  However, a change of scale would change the
correspondence between data and axes coords, so the axes transform
part of the blended axes would have to be recomputed everytime the
scale changes based on where the (x,y1) point lands in the axes.  Is
this correct?

Any suggestions are welcome...thanks!

Uri




------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA






--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.transforms as mtransforms
import matplotlib.path as mpath

class MyBox(mpatches.Patch):

   def __init__(self, x, w, y1, y2, **kwargs):
      self.x = x
      self.w = w
      self.y1 = y1
      self.y2 = y2
      mpatches.Patch.__init__(self, **kwargs)

   def get_path(self):
      return mpath.Path.unit_rectangle()

   def get_transform(self):

      # Transform the data-relative values
      box = [[self.x, self.y1],
             [self.x, self.y2]]
      box = self.axes.transData.transform(box)

      # Get the width as a fraction of the axes width
      w = self.w * self.axes.bbox.width / 2.0

      # Add it to the data-transformed coordinates
      box[0][0] -= w
      box[1][0] += w

      return mtransforms.BboxTransformTo(mtransforms.Bbox(box))

fig = plt.figure()
ax = fig.add_subplot(111)
patch = MyBox(0, 0.1, 0.5, 1.5)
ax.add_patch(patch)
ax.set_xlim((-1, 1))
ax.set_ylim((0, 2))

plt.show()
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to