Exemple #1
0
    def set_bounds(self, vmin, vmax):
        '''
        Set dataInterval and viewInterval from numeric vmin, vmax.

        This is for stand-alone use of Formatters and/or
        Locators that require these intervals; that is, for
        cases where the Intervals do not need to be updated
        automatically.
        '''
        self.dataInterval = mtrans.Interval(mtrans.Value(vmin),
                                            mtrans.Value(vmax))
        self.viewInterval = mtrans.Interval(mtrans.Value(vmin),
                                            mtrans.Value(vmax))
Exemple #2
0
 def _set_transform(self):
     ax = self.ax
     if self.units in ('x', 'y'):
         if self.units == 'x':
             dx0 = ax.viewLim.ur().x() - ax.viewLim.ll().x()
             dx1 = ax.bbox.ur().x() - ax.bbox.ll().x()
         else:
             dx0 = ax.viewLim.ur().y() - ax.viewLim.ll().y()
             dx1 = ax.bbox.ur().y() - ax.bbox.ll().y()
         dx = dx1/dx0
     else:
         if self.units == 'width':
             dx = ax.bbox.ur().x() - ax.bbox.ll().x()
         elif self.units == 'height':
             dx = ax.bbox.ur().y() - ax.bbox.ll().y()
         elif self.units == 'dots':
             dx = T.Value(1)
         elif self.units == 'inches':
             dx = ax.figure.dpi
         else:
             raise ValueError('unrecognized units')
     bb = T.Bbox(T.origin(), T.Point(dx, dx))
     trans = T.get_bbox_transform(T.unit_bbox(), bb)
     self.set_transform(trans)
     return trans
Exemple #3
0
 def _ticker(self):
     '''
     Return two sequences: ticks (colorbar data locations)
     and ticklabels (strings).
     '''
     locator = self.locator
     formatter = self.formatter
     if locator is None:
         if self.boundaries is None:
             if isinstance(self.norm, colors.NoNorm):
                 nv = len(self._values)
                 base = 1 + int(nv / 10)
                 locator = ticker.IndexLocator(base=base, offset=0)
             elif isinstance(self.norm, colors.LogNorm):
                 locator = ticker.LogLocator()
             else:
                 locator = ticker.MaxNLocator()
         else:
             b = self._boundaries[self._inside]
             locator = ticker.FixedLocator(b, nbins=10)
     if isinstance(self.norm, colors.NoNorm):
         intv = transforms.Interval(transforms.Value(self._values[0]),
                                    transforms.Value(self._values[-1]))
     else:
         intv = transforms.Interval(transforms.Value(self.vmin),
                                    transforms.Value(self.vmax))
     locator.set_view_interval(intv)
     locator.set_data_interval(intv)
     formatter.set_view_interval(intv)
     formatter.set_data_interval(intv)
     b = npy.array(locator())
     b, ticks = self._locate(b)
     formatter.set_locs(b)
     ticklabels = [formatter(t) for t in b]
     offset_string = formatter.get_offset()
     return ticks, ticklabels, offset_string
Exemple #4
0
 def __init__(self, Q, X, Y, U, label, **kw):
     Artist.__init__(self)
     self.Q = Q
     self.X = X
     self.Y = Y
     self.U = U
     self.coord = kw.pop('coordinates', 'axes')
     self.color = kw.pop('color', None)
     self.label = label
     self.labelsep = T.Value(kw.pop('labelsep', 0.1)) * Q.ax.figure.dpi
     self.labelpos = kw.pop('labelpos', 'N')
     self.labelcolor = kw.pop('labelcolor', None)
     self.fontproperties = kw.pop('fontproperties', dict())
     self.kw = kw
     self.text = Text(text=label,
                      horizontalalignment=self.halign[self.labelpos],
                      verticalalignment=self.valign[self.labelpos],
                      fontproperties=FontProperties(**self.fontproperties))
     if self.labelcolor is not None:
         self.text.set_color(self.labelcolor)
     self._initialized = False
     self.zorder = Q.zorder + 0.1
                                 transOffset=a.transData)
# Note: the first argument to the collection initializer
# must be a list of sequences of x,y tuples; we have only
# one sequence, but we still have to put it in a list.
a.add_collection(col, autolim=True)
# autolim=True enables autoscaling.  For collections with
# offsets like this, it is neither efficient nor accurate,
# but it is good enough to generate a plot that you can use
# as a starting point.  If you know beforehand the range of
# x and y that you want to show, it is better to set them
# explicitly, leave out the autolim kwarg (or set it to False),
# and omit the 'a.autoscale_view()' call below.

# Make a transform for the line segments such that their size is
# given in points:
trans = transforms.scale_transform(fig.dpi / transforms.Value(72.),
                                   fig.dpi / transforms.Value(72.))
col.set_transform(trans)  # the points to pixels transform
col.set_color(colors)

a.autoscale_view()  # See comment above, after a.add_collection.
a.set_title('LineCollection using offsets')

# The same data as above, but fill the curves.

a = fig.add_subplot(2, 2, 2)

col = collections.PolyCollection([spiral],
                                 offsets=xyo,
                                 transOffset=a.transData)
a.add_collection(col, autolim=True)