desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'return the path of the arrow in the data coordinate. Use
get_path_in_displaycoord() medthod to retrieve the arrow path
in the disaply coord.'
| def get_path(self):
| _path = self.get_path_in_displaycoord()
return self.get_transform().inverted().transform_path(_path)
|
'Return the mutated path of the arrow in the display coord'
| def get_path_in_displaycoord(self):
| if (self._posA_posB is not None):
posA = self.get_transform().transform_point(self._posA_posB[0])
posB = self.get_transform().transform_point(self._posA_posB[1])
_path = self.get_connectionstyle()(posA, posB, patchA=self.patchA, patchB=self.patchB, shrinkA=self.shrinkA, shrinkB=self.shrinkB)
else:
_path = self.get_transform().transform_path(self._path_original)
(_path, closed) = self.get_arrowstyle()(_path, self.get_mutation_scale(), self.get_linewidth(), self.get_mutation_aspect())
if (not closed):
self.fill = False
return _path
|
'Split the Type 1 font into its three main parts.
The three parts are: (1) the cleartext part, which ends in a
eexec operator; (2) the encrypted part; (3) the fixed part,
which contains 512 ASCII zeros possibly divided on various
lines, a cleartomark operator, and possibly something else.'
| def _split(self, data):
| idx = data.index('eexec')
idx += len('eexec')
while (data[idx] in ' DCTB \r\n'):
idx += 1
len1 = idx
idx = (data.rindex('cleartomark') - 1)
zeros = 512
while (zeros and (data[idx] in ('0', '\n', '\r'))):
if (data[idx] == '0'):
zeros -= 1
idx -= 1
if zeros:
raise RuntimeError, 'Insufficiently many zeros in Type 1 font'
binary = ''.join([chr(int(data[i:(i + 2)], 16)) for i in range(len1, idx, 2)])
return (data[:len1], binary, data[idx:])
|
'A very limited kind of parsing to find the Encoding of the
font.'
| def _parse(self):
| def tokens(text):
'\n Yield pairs (position, token), ignoring comments and\n whitespace. Numbers count as tokens.\n '
pos = 0
while (pos < len(text)):
match = (self._comment.match(text[pos:]) or self._whitespace.match(text[pos:]))
if match:
pos += match.end()
elif (text[pos] == '('):
start = pos
pos += 1
depth = 1
while depth:
match = self._instring.search(text[pos:])
if (match is None):
return
if (match.group() == '('):
depth += 1
pos += 1
elif (match.group() == ')'):
depth -= 1
pos += 1
else:
pos += 2
(yield (start, text[start:pos]))
elif (text[pos:(pos + 2)] in ('<<', '>>')):
(yield (pos, text[pos:(pos + 2)]))
pos += 2
elif (text[pos] == '<'):
start = pos
pos += text[pos:].index('>')
(yield (start, text[start:pos]))
else:
match = self._token.match(text[pos:])
if match:
(yield (pos, match.group()))
pos += match.end()
else:
(yield (pos, text[pos]))
pos += 1
(enc_starts, enc_ends) = (None, None)
state = 0
for (pos, token) in tokens(self.parts[0]):
if ((state == 0) and (token == '/Encoding')):
enc_starts = pos
state = 1
elif ((state == 1) and (token == 'StandardEncoding')):
state = 2
elif ((state in (2, 5)) and (token == 'def')):
enc_ends = (pos + 3)
break
elif ((state in (1, 5)) and (token == 'dup')):
state = 4
elif ((state == 4) and (token == 'put')):
state = 5
(self.enc_starts, self.enc_ends) = (enc_starts, enc_ends)
|
'bbox is the Bound2D bounding box in display coords of the Axes
loc is the tick location in data coords
size is the tick size in relative, axes coords'
| def __init__(self, axes, loc, label, size=None, gridOn=None, tick1On=True, tick2On=True, label1On=True, label2On=False, major=True):
| artist.Artist.__init__(self)
if (gridOn is None):
gridOn = rcParams['axes.grid']
self.set_figure(axes.figure)
self.axes = axes
name = self.__name__.lower()
if (size is None):
if major:
size = rcParams[('%s.major.size' % name)]
pad = rcParams[('%s.major.pad' % name)]
else:
size = rcParams[('%s.minor.size' % name)]
pad = rcParams[('%s.minor.pad' % name)]
self._tickdir = rcParams[('%s.direction' % name)]
if (self._tickdir == 'in'):
self._xtickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
self._ytickmarkers = (mlines.TICKRIGHT, mlines.TICKLEFT)
self._pad = pad
else:
self._xtickmarkers = (mlines.TICKDOWN, mlines.TICKUP)
self._ytickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT)
self._pad = (pad + size)
self._loc = loc
self._size = size
self.tick1line = self._get_tick1line()
self.tick2line = self._get_tick2line()
self.gridline = self._get_gridline()
self.label1 = self._get_text1()
self.label = self.label1
self.label2 = self._get_text2()
self.gridOn = gridOn
self.tick1On = tick1On
self.tick2On = tick2On
self.label1On = label1On
self.label2On = label2On
self.update_position(loc)
|
'Test whether the mouse event occured in the Tick marks.
This function always returns false. It is more useful to test if the
axis as a whole contains the mouse rather than the set of tick marks.'
| def contains(self, mouseevent):
| if callable(self._contains):
return self._contains(self, mouseevent)
return (False, {})
|
'Set the tick label pad in points
ACCEPTS: float'
| def set_pad(self, val):
| self._pad = val
|
'Get the value of the tick label pad in points'
| def get_pad(self):
| return self._pad
|
'Get the default Text 1 instance'
| def _get_text1(self):
| pass
|
'Get the default Text 2 instance'
| def _get_text2(self):
| pass
|
'Get the default line2D instance for tick1'
| def _get_tick1line(self):
| pass
|
'Get the default line2D instance for tick2'
| def _get_tick2line(self):
| pass
|
'Get the default grid Line2d instance for this tick'
| def _get_gridline(self):
| pass
|
'Return the tick location (data coords) as a scalar'
| def get_loc(self):
| return self._loc
|
'Set the text of ticklabel
ACCEPTS: str'
| def set_label1(self, s):
| self.label1.set_text(s)
|
'Set the text of ticklabel2
ACCEPTS: str'
| def set_label2(self, s):
| self.label2.set_text(s)
|
'return the view Interval instance for the axis this tick is ticking'
| def get_view_interval(self):
| raise NotImplementedError('Derived must override')
|
'Get the default Text instance'
| def _get_text1(self):
| (trans, vert, horiz) = self.axes.get_xaxis_text1_transform(self._pad)
size = rcParams['xtick.labelsize']
t = mtext.Text(x=0, y=0, fontproperties=font_manager.FontProperties(size=size), color=rcParams['xtick.color'], verticalalignment=vert, horizontalalignment=horiz)
t.set_transform(trans)
self._set_artist_props(t)
return t
|
'Get the default Text 2 instance'
| def _get_text2(self):
| (trans, vert, horiz) = self.axes.get_xaxis_text2_transform(self._pad)
t = mtext.Text(x=0, y=1, fontproperties=font_manager.FontProperties(size=rcParams['xtick.labelsize']), color=rcParams['xtick.color'], verticalalignment=vert, horizontalalignment=horiz)
t.set_transform(trans)
self._set_artist_props(t)
return t
|
'Get the default line2D instance'
| def _get_tick1line(self):
| l = mlines.Line2D(xdata=(0,), ydata=(0,), color='k', linestyle='None', marker=self._xtickmarkers[0], markersize=self._size)
l.set_transform(self.axes.get_xaxis_transform())
self._set_artist_props(l)
return l
|
'Get the default line2D instance'
| def _get_tick2line(self):
| l = mlines.Line2D(xdata=(0,), ydata=(1,), color='k', linestyle='None', marker=self._xtickmarkers[1], markersize=self._size)
l.set_transform(self.axes.get_xaxis_transform())
self._set_artist_props(l)
return l
|
'Get the default line2D instance'
| def _get_gridline(self):
| l = mlines.Line2D(xdata=(0.0, 0.0), ydata=(0, 1.0), color=rcParams['grid.color'], linestyle=rcParams['grid.linestyle'], linewidth=rcParams['grid.linewidth'])
l.set_transform(self.axes.get_xaxis_transform())
self._set_artist_props(l)
return l
|
'Set the location of tick in data coords with scalar *loc*'
| def update_position(self, loc):
| x = loc
nonlinear = ((hasattr(self.axes, 'yaxis') and (self.axes.yaxis.get_scale() != 'linear')) or (hasattr(self.axes, 'xaxis') and (self.axes.xaxis.get_scale() != 'linear')))
if self.tick1On:
self.tick1line.set_xdata((x,))
if self.tick2On:
self.tick2line.set_xdata((x,))
if self.gridOn:
self.gridline.set_xdata((x,))
if self.label1On:
self.label1.set_x(x)
if self.label2On:
self.label2.set_x(x)
if nonlinear:
self.tick1line._invalid = True
self.tick2line._invalid = True
self.gridline._invalid = True
self._loc = loc
|
'return the Interval instance for this axis view limits'
| def get_view_interval(self):
| return self.axes.viewLim.intervalx
|
'return the Interval instance for this axis data limits'
| def get_data_interval(self):
| return self.axes.dataLim.intervalx
|
'Get the default Text instance'
| def _get_text1(self):
| (trans, vert, horiz) = self.axes.get_yaxis_text1_transform(self._pad)
t = mtext.Text(x=0, y=0, fontproperties=font_manager.FontProperties(size=rcParams['ytick.labelsize']), color=rcParams['ytick.color'], verticalalignment=vert, horizontalalignment=horiz)
t.set_transform(trans)
self._set_artist_props(t)
return t
|
'Get the default Text instance'
| def _get_text2(self):
| (trans, vert, horiz) = self.axes.get_yaxis_text2_transform(self._pad)
t = mtext.Text(x=1, y=0, fontproperties=font_manager.FontProperties(size=rcParams['ytick.labelsize']), color=rcParams['ytick.color'], verticalalignment=vert, horizontalalignment=horiz)
t.set_transform(trans)
self._set_artist_props(t)
return t
|
'Get the default line2D instance'
| def _get_tick1line(self):
| l = mlines.Line2D((0,), (0,), color='k', marker=self._ytickmarkers[0], linestyle='None', markersize=self._size)
l.set_transform(self.axes.get_yaxis_transform())
self._set_artist_props(l)
return l
|
'Get the default line2D instance'
| def _get_tick2line(self):
| l = mlines.Line2D((1,), (0,), color='k', marker=self._ytickmarkers[1], linestyle='None', markersize=self._size)
l.set_transform(self.axes.get_yaxis_transform())
self._set_artist_props(l)
return l
|
'Get the default line2D instance'
| def _get_gridline(self):
| l = mlines.Line2D(xdata=(0, 1), ydata=(0, 0), color=rcParams['grid.color'], linestyle=rcParams['grid.linestyle'], linewidth=rcParams['grid.linewidth'])
l.set_transform(self.axes.get_yaxis_transform())
self._set_artist_props(l)
return l
|
'Set the location of tick in data coords with scalar loc'
| def update_position(self, loc):
| y = loc
nonlinear = ((hasattr(self.axes, 'yaxis') and (self.axes.yaxis.get_scale() != 'linear')) or (hasattr(self.axes, 'xaxis') and (self.axes.xaxis.get_scale() != 'linear')))
if self.tick1On:
self.tick1line.set_ydata((y,))
if self.tick2On:
self.tick2line.set_ydata((y,))
if self.gridOn:
self.gridline.set_ydata((y,))
if self.label1On:
self.label1.set_y(y)
if self.label2On:
self.label2.set_y(y)
if nonlinear:
self.tick1line._invalid = True
self.tick2line._invalid = True
self.gridline._invalid = True
self._loc = loc
|
'return the Interval instance for this axis view limits'
| def get_view_interval(self):
| return self.axes.viewLim.intervaly
|
'return the Interval instance for this axis data limits'
| def get_data_interval(self):
| return self.axes.dataLim.intervaly
|
'Init the axis with the parent Axes instance'
| def __init__(self, axes, pickradius=15):
| artist.Artist.__init__(self)
self.set_figure(axes.figure)
self.axes = axes
self.major = Ticker()
self.minor = Ticker()
self.callbacks = cbook.CallbackRegistry(('units', 'units finalize'))
self._autolabelpos = True
self.label = self._get_label()
self.offsetText = self._get_offset_text()
self.majorTicks = []
self.minorTicks = []
self.pickradius = pickradius
self.cla()
self.set_scale('linear')
|
'Set the coordinates of the label. By default, the x
coordinate of the y label is determined by the tick label
bounding boxes, but this can lead to poor alignment of
multiple ylabels if there are multiple axes. Ditto for the y
coodinate of the x label.
You can also specify the coordinate system of the label with
the transform. If None, the default coordinate system will be
the axes coordinate system (0,0) is (left,bottom), (0.5, 0.5)
is middle, etc'
| def set_label_coords(self, x, y, transform=None):
| self._autolabelpos = False
if (transform is None):
transform = self.axes.transAxes
self.label.set_transform(transform)
self.label.set_position((x, y))
|
'clear the current axis'
| def cla(self):
| self.set_major_locator(mticker.AutoLocator())
self.set_major_formatter(mticker.ScalarFormatter())
self.set_minor_locator(mticker.NullLocator())
self.set_minor_formatter(mticker.NullFormatter())
self.callbacks = cbook.CallbackRegistry(('units', 'units finalize'))
self._gridOnMajor = rcParams['axes.grid']
self._gridOnMinor = False
self.label.set_text('')
self._set_artist_props(self.label)
cbook.popall(self.majorTicks)
cbook.popall(self.minorTicks)
self.majorTicks.extend([self._get_tick(major=True)])
self.minorTicks.extend([self._get_tick(major=False)])
self._lastNumMajorTicks = 1
self._lastNumMinorTicks = 1
self.converter = None
self.units = None
self.set_units(None)
|
'return the Interval instance for this axis view limits'
| def get_view_interval(self):
| raise NotImplementedError('Derived must override')
|
'return the Interval instance for this axis data limits'
| def get_data_interval(self):
| raise NotImplementedError('Derived must override')
|
'Set the axis data limits'
| def set_data_interval(self):
| raise NotImplementedError('Derived must override')
|
'Iterate through all of the major and minor ticks.'
| def iter_ticks(self):
| majorLocs = self.major.locator()
majorTicks = self.get_major_ticks(len(majorLocs))
self.major.formatter.set_locs(majorLocs)
majorLabels = [self.major.formatter(val, i) for (i, val) in enumerate(majorLocs)]
minorLocs = self.minor.locator()
minorTicks = self.get_minor_ticks(len(minorLocs))
self.minor.formatter.set_locs(minorLocs)
minorLabels = [self.minor.formatter(val, i) for (i, val) in enumerate(minorLocs)]
major_minor = [(majorTicks, majorLocs, majorLabels), (minorTicks, minorLocs, minorLabels)]
for group in major_minor:
for tick in zip(*group):
(yield tick)
|
'Get the extents of the tick labels on either side
of the axes.'
| def get_ticklabel_extents(self, renderer):
| ticklabelBoxes = []
ticklabelBoxes2 = []
interval = self.get_view_interval()
for (tick, loc, label) in self.iter_ticks():
if (tick is None):
continue
if (not mtransforms.interval_contains(interval, loc)):
continue
tick.update_position(loc)
tick.set_label1(label)
tick.set_label2(label)
if (tick.label1On and tick.label1.get_visible()):
extent = tick.label1.get_window_extent(renderer)
ticklabelBoxes.append(extent)
if (tick.label2On and tick.label2.get_visible()):
extent = tick.label2.get_window_extent(renderer)
ticklabelBoxes2.append(extent)
if len(ticklabelBoxes):
bbox = mtransforms.Bbox.union(ticklabelBoxes)
else:
bbox = mtransforms.Bbox.from_extents(0, 0, 0, 0)
if len(ticklabelBoxes2):
bbox2 = mtransforms.Bbox.union(ticklabelBoxes2)
else:
bbox2 = mtransforms.Bbox.from_extents(0, 0, 0, 0)
return (bbox, bbox2)
|
'Draw the axis lines, grid lines, tick lines and labels'
| def draw(self, renderer, *args, **kwargs):
| ticklabelBoxes = []
ticklabelBoxes2 = []
if (not self.get_visible()):
return
renderer.open_group(__name__)
interval = self.get_view_interval()
for (tick, loc, label) in self.iter_ticks():
if (tick is None):
continue
if (not mtransforms.interval_contains(interval, loc)):
continue
tick.update_position(loc)
tick.set_label1(label)
tick.set_label2(label)
tick.draw(renderer)
if (tick.label1On and tick.label1.get_visible()):
extent = tick.label1.get_window_extent(renderer)
ticklabelBoxes.append(extent)
if (tick.label2On and tick.label2.get_visible()):
extent = tick.label2.get_window_extent(renderer)
ticklabelBoxes2.append(extent)
self._update_label_position(ticklabelBoxes, ticklabelBoxes2)
self.label.draw(renderer)
self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
self.offsetText.set_text(self.major.formatter.get_offset())
self.offsetText.draw(renderer)
if 0:
for tick in majorTicks:
label = tick.label1
mpatches.bbox_artist(label, renderer)
mpatches.bbox_artist(self.label, renderer)
renderer.close_group(__name__)
|
'Return the grid lines as a list of Line2D instance'
| def get_gridlines(self):
| ticks = self.get_major_ticks()
return cbook.silent_list('Line2D gridline', [tick.gridline for tick in ticks])
|
'Return the axis label as a Text instance'
| def get_label(self):
| return self.label
|
'Return the axis offsetText as a Text instance'
| def get_offset_text(self):
| return self.offsetText
|
'Return the depth of the axis used by the picker'
| def get_pickradius(self):
| return self.pickradius
|
'Return a list of Text instances for the major ticklabels'
| def get_majorticklabels(self):
| ticks = self.get_major_ticks()
labels1 = [tick.label1 for tick in ticks if tick.label1On]
labels2 = [tick.label2 for tick in ticks if tick.label2On]
return cbook.silent_list('Text major ticklabel', (labels1 + labels2))
|
'Return a list of Text instances for the minor ticklabels'
| def get_minorticklabels(self):
| ticks = self.get_minor_ticks()
labels1 = [tick.label1 for tick in ticks if tick.label1On]
labels2 = [tick.label2 for tick in ticks if tick.label2On]
return cbook.silent_list('Text minor ticklabel', (labels1 + labels2))
|
'Return a list of Text instances for ticklabels'
| def get_ticklabels(self, minor=False):
| if minor:
return self.get_minorticklabels()
return self.get_majorticklabels()
|
'Return the major tick lines as a list of Line2D instances'
| def get_majorticklines(self):
| lines = []
ticks = self.get_major_ticks()
for tick in ticks:
lines.append(tick.tick1line)
lines.append(tick.tick2line)
return cbook.silent_list('Line2D ticklines', lines)
|
'Return the minor tick lines as a list of Line2D instances'
| def get_minorticklines(self):
| lines = []
ticks = self.get_minor_ticks()
for tick in ticks:
lines.append(tick.tick1line)
lines.append(tick.tick2line)
return cbook.silent_list('Line2D ticklines', lines)
|
'Return the tick lines as a list of Line2D instances'
| def get_ticklines(self, minor=False):
| if minor:
return self.get_minorticklines()
return self.get_majorticklines()
|
'Get the major tick locations in data coordinates as a numpy array'
| def get_majorticklocs(self):
| return self.major.locator()
|
'Get the minor tick locations in data coordinates as a numpy array'
| def get_minorticklocs(self):
| return self.minor.locator()
|
'Get the tick locations in data coordinates as a numpy array'
| def get_ticklocs(self, minor=False):
| if minor:
return self.minor.locator()
return self.major.locator()
|
'return the default tick intsance'
| def _get_tick(self, major):
| raise NotImplementedError('derived must override')
|
'Copy the props from src tick to dest tick'
| def _copy_tick_props(self, src, dest):
| if ((src is None) or (dest is None)):
return
dest.label1.update_from(src.label1)
dest.label2.update_from(src.label2)
dest.tick1line.update_from(src.tick1line)
dest.tick2line.update_from(src.tick2line)
dest.gridline.update_from(src.gridline)
dest.tick1On = src.tick1On
dest.tick2On = src.tick2On
dest.label1On = src.label1On
dest.label2On = src.label2On
|
'Get the locator of the major ticker'
| def get_major_locator(self):
| return self.major.locator
|
'Get the locator of the minor ticker'
| def get_minor_locator(self):
| return self.minor.locator
|
'Get the formatter of the major ticker'
| def get_major_formatter(self):
| return self.major.formatter
|
'Get the formatter of the minor ticker'
| def get_minor_formatter(self):
| return self.minor.formatter
|
'get the tick instances; grow as necessary'
| def get_major_ticks(self, numticks=None):
| if (numticks is None):
numticks = len(self.get_major_locator()())
if (len(self.majorTicks) < numticks):
for i in range((numticks - len(self.majorTicks))):
tick = self._get_tick(major=True)
self.majorTicks.append(tick)
if (self._lastNumMajorTicks < numticks):
protoTick = self.majorTicks[0]
for i in range(self._lastNumMajorTicks, len(self.majorTicks)):
tick = self.majorTicks[i]
if self._gridOnMajor:
tick.gridOn = True
self._copy_tick_props(protoTick, tick)
self._lastNumMajorTicks = numticks
ticks = self.majorTicks[:numticks]
return ticks
|
'get the minor tick instances; grow as necessary'
| def get_minor_ticks(self, numticks=None):
| if (numticks is None):
numticks = len(self.get_minor_locator()())
if (len(self.minorTicks) < numticks):
for i in range((numticks - len(self.minorTicks))):
tick = self._get_tick(major=False)
self.minorTicks.append(tick)
if (self._lastNumMinorTicks < numticks):
protoTick = self.minorTicks[0]
for i in range(self._lastNumMinorTicks, len(self.minorTicks)):
tick = self.minorTicks[i]
if self._gridOnMinor:
tick.gridOn = True
self._copy_tick_props(protoTick, tick)
self._lastNumMinorTicks = numticks
ticks = self.minorTicks[:numticks]
return ticks
|
'Set the axis grid on or off; b is a boolean use *which* =
\'major\' | \'minor\' to set the grid for major or minor ticks
if *b* is *None* and len(kwargs)==0, toggle the grid state. If
*kwargs* are supplied, it is assumed you want the grid on and *b*
will be set to True
*kwargs* are used to set the line properties of the grids, eg,
xax.grid(color=\'r\', linestyle=\'-\', linewidth=2)'
| def grid(self, b=None, which='major', **kwargs):
| if len(kwargs):
b = True
if (which.lower().find('minor') >= 0):
if (b is None):
self._gridOnMinor = (not self._gridOnMinor)
else:
self._gridOnMinor = b
for tick in self.minorTicks:
if (tick is None):
continue
tick.gridOn = self._gridOnMinor
if len(kwargs):
artist.setp(tick.gridline, **kwargs)
else:
if (b is None):
self._gridOnMajor = (not self._gridOnMajor)
else:
self._gridOnMajor = b
for tick in self.majorTicks:
if (tick is None):
continue
tick.gridOn = self._gridOnMajor
if len(kwargs):
artist.setp(tick.gridline, **kwargs)
|
'introspect *data* for units converter and update the
axis.converter instance if necessary. Return *True* is *data* is
registered for unit conversion'
| def update_units(self, data):
| converter = munits.registry.get_converter(data)
if (converter is None):
return False
self.converter = converter
default = self.converter.default_units(data)
if ((default is not None) and (self.units is None)):
self.set_units(default)
self._update_axisinfo()
return True
|
'check the axis converter for the stored units to see if the
axis info needs to be updated'
| def _update_axisinfo(self):
| if (self.converter is None):
return
info = self.converter.axisinfo(self.units)
if (info is None):
return
if ((info.majloc is not None) and (self.major.locator != info.majloc)):
self.set_major_locator(info.majloc)
if ((info.minloc is not None) and (self.minor.locator != info.minloc)):
self.set_minor_locator(info.minloc)
if ((info.majfmt is not None) and (self.major.formatter != info.majfmt)):
self.set_major_formatter(info.majfmt)
if ((info.minfmt is not None) and (self.minor.formatter != info.minfmt)):
self.set_minor_formatter(info.minfmt)
if (info.label is not None):
label = self.get_label()
label.set_text(info.label)
|
'set the units for axis
ACCEPTS: a units tag'
| def set_units(self, u):
| pchanged = False
if (u is None):
self.units = None
pchanged = True
elif (u != self.units):
self.units = u
pchanged = True
if pchanged:
self._update_axisinfo()
self.callbacks.process('units')
self.callbacks.process('units finalize')
|
'return the units for axis'
| def get_units(self):
| return self.units
|
'Set the formatter of the major ticker
ACCEPTS: A :class:`~matplotlib.ticker.Formatter` instance'
| def set_major_formatter(self, formatter):
| self.major.formatter = formatter
formatter.set_axis(self)
|
'Set the formatter of the minor ticker
ACCEPTS: A :class:`~matplotlib.ticker.Formatter` instance'
| def set_minor_formatter(self, formatter):
| self.minor.formatter = formatter
formatter.set_axis(self)
|
'Set the locator of the major ticker
ACCEPTS: a :class:`~matplotlib.ticker.Locator` instance'
| def set_major_locator(self, locator):
| self.major.locator = locator
locator.set_axis(self)
|
'Set the locator of the minor ticker
ACCEPTS: a :class:`~matplotlib.ticker.Locator` instance'
| def set_minor_locator(self, locator):
| self.minor.locator = locator
locator.set_axis(self)
|
'Set the depth of the axis used by the picker
ACCEPTS: a distance in points'
| def set_pickradius(self, pickradius):
| self.pickradius = pickradius
|
'Set the text values of the tick labels. Return a list of Text
instances. Use *kwarg* *minor=True* to select minor ticks.
ACCEPTS: sequence of strings'
| def set_ticklabels(self, ticklabels, *args, **kwargs):
| minor = kwargs.pop('minor', False)
if minor:
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
ticks = self.get_minor_ticks()
else:
self.set_major_formatter(mticker.FixedFormatter(ticklabels))
ticks = self.get_major_ticks()
self.set_major_formatter(mticker.FixedFormatter(ticklabels))
ret = []
for (i, tick) in enumerate(ticks):
if (i < len(ticklabels)):
tick.label1.set_text(ticklabels[i])
ret.append(tick.label1)
tick.label1.update(kwargs)
return ret
|
'Set the locations of the tick marks from sequence ticks
ACCEPTS: sequence of floats'
| def set_ticks(self, ticks, minor=False):
| ticks = self.convert_units(ticks)
if (len(ticks) > 1):
(xleft, xright) = self.get_view_interval()
if (xright > xleft):
self.set_view_interval(min(ticks), max(ticks))
else:
self.set_view_interval(max(ticks), min(ticks))
if minor:
self.set_minor_locator(mticker.FixedLocator(ticks))
return self.get_minor_ticks(len(ticks))
else:
self.set_major_locator(mticker.FixedLocator(ticks))
return self.get_major_ticks(len(ticks))
|
'Update the label position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_label_position(self, bboxes, bboxes2):
| raise NotImplementedError('Derived must override')
|
'Update the label position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_offset_text_postion(self, bboxes, bboxes2):
| raise NotImplementedError('Derived must override')
|
'Pan *numsteps* (can be positive or negative)'
| def pan(self, numsteps):
| self.major.locator.pan(numsteps)
|
'Zoom in/out on axis; if *direction* is >0 zoom in, else zoom out'
| def zoom(self, direction):
| self.major.locator.zoom(direction)
|
'Test whether the mouse event occured in the x axis.'
| def contains(self, mouseevent):
| if callable(self._contains):
return self._contains(self, mouseevent)
(x, y) = (mouseevent.x, mouseevent.y)
try:
trans = self.axes.transAxes.inverted()
(xaxes, yaxes) = trans.transform_point((x, y))
except ValueError:
return (False, {})
(l, b) = self.axes.transAxes.transform_point((0, 0))
(r, t) = self.axes.transAxes.transform_point((1, 1))
inaxis = ((xaxes >= 0) and (xaxes <= 1) and (((y < b) and (y > (b - self.pickradius))) or ((y > t) and (y < (t + self.pickradius)))))
return (inaxis, {})
|
'Return the label position (top or bottom)'
| def get_label_position(self):
| return self.label_position
|
'Set the label position (top or bottom)
ACCEPTS: [ \'top\' | \'bottom\' ]'
| def set_label_position(self, position):
| assert ((position == 'top') or (position == 'bottom'))
if (position == 'top'):
self.label.set_verticalalignment('bottom')
else:
self.label.set_verticalalignment('top')
self.label_position = position
|
'Update the label position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_label_position(self, bboxes, bboxes2):
| if (not self._autolabelpos):
return
(x, y) = self.label.get_position()
if (self.label_position == 'bottom'):
if (not len(bboxes)):
bottom = self.axes.bbox.ymin
else:
bbox = mtransforms.Bbox.union(bboxes)
bottom = bbox.y0
self.label.set_position((x, (bottom - ((self.LABELPAD * self.figure.dpi) / 72.0))))
else:
if (not len(bboxes2)):
top = self.axes.bbox.ymax
else:
bbox = mtransforms.Bbox.union(bboxes2)
top = bbox.y1
self.label.set_position((x, (top + ((self.LABELPAD * self.figure.dpi) / 72.0))))
|
'Update the offset_text position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_offset_text_position(self, bboxes, bboxes2):
| (x, y) = self.offsetText.get_position()
if (not len(bboxes)):
bottom = self.axes.bbox.ymin
else:
bbox = mtransforms.Bbox.union(bboxes)
bottom = bbox.y0
self.offsetText.set_position((x, (bottom - ((self.OFFSETTEXTPAD * self.figure.dpi) / 72.0))))
|
'Returns the amount of space one should reserve for text
above and below the axes. Returns a tuple (above, below)'
| def get_text_heights(self, renderer):
| (bbox, bbox2) = self.get_ticklabel_extents(renderer)
padPixels = self.majorTicks[0].get_pad_pixels()
above = 0.0
if bbox2.height:
above += (bbox2.height + padPixels)
below = 0.0
if bbox.height:
below += (bbox.height + padPixels)
if (self.get_label_position() == 'top'):
above += (self.label.get_window_extent(renderer).height + padPixels)
else:
below += (self.label.get_window_extent(renderer).height + padPixels)
return (above, below)
|
'Set the ticks position (top, bottom, both, default or none)
both sets the ticks to appear on both positions, but does not
change the tick labels. default resets the tick positions to
the default: ticks on both positions, labels at bottom. none
can be used if you don\'t want any ticks.
ACCEPTS: [ \'top\' | \'bottom\' | \'both\' | \'default\' | \'none\' ]'
| def set_ticks_position(self, position):
| assert (position in ('top', 'bottom', 'both', 'default', 'none'))
ticks = list(self.get_major_ticks())
ticks.extend(self.get_minor_ticks())
if (position == 'top'):
for t in ticks:
t.tick1On = False
t.tick2On = True
t.label1On = False
t.label2On = True
elif (position == 'bottom'):
for t in ticks:
t.tick1On = True
t.tick2On = False
t.label1On = True
t.label2On = False
elif (position == 'default'):
for t in ticks:
t.tick1On = True
t.tick2On = True
t.label1On = True
t.label2On = False
elif (position == 'none'):
for t in ticks:
t.tick1On = False
t.tick2On = False
else:
for t in ticks:
t.tick1On = True
t.tick2On = True
for t in ticks:
t.update_position(t._loc)
|
'use ticks only on top'
| def tick_top(self):
| self.set_ticks_position('top')
|
'use ticks only on bottom'
| def tick_bottom(self):
| self.set_ticks_position('bottom')
|
'Return the ticks position (top, bottom, default or unknown)'
| def get_ticks_position(self):
| majt = self.majorTicks[0]
mT = self.minorTicks[0]
majorTop = ((not majt.tick1On) and majt.tick2On and (not majt.label1On) and majt.label2On)
minorTop = ((not mT.tick1On) and mT.tick2On and (not mT.label1On) and mT.label2On)
if (majorTop and minorTop):
return 'top'
MajorBottom = (majt.tick1On and (not majt.tick2On) and majt.label1On and (not majt.label2On))
MinorBottom = (mT.tick1On and (not mT.tick2On) and mT.label1On and (not mT.label2On))
if (MajorBottom and MinorBottom):
return 'bottom'
majorDefault = (majt.tick1On and majt.tick2On and majt.label1On and (not majt.label2On))
minorDefault = (mT.tick1On and mT.tick2On and mT.label1On and (not mT.label2On))
if (majorDefault and minorDefault):
return 'default'
return 'unknown'
|
'return the Interval instance for this axis view limits'
| def get_view_interval(self):
| return self.axes.viewLim.intervalx
|
'return the Interval instance for this axis data limits'
| def get_data_interval(self):
| return self.axes.dataLim.intervalx
|
'return the Interval instance for this axis data limits'
| def set_data_interval(self, vmin, vmax, ignore=False):
| if ignore:
self.axes.dataLim.intervalx = (vmin, vmax)
else:
(Vmin, Vmax) = self.get_data_interval()
self.axes.dataLim.intervalx = (min(vmin, Vmin), max(vmax, Vmax))
|
'Test whether the mouse event occurred in the y axis.
Returns *True* | *False*'
| def contains(self, mouseevent):
| if callable(self._contains):
return self._contains(self, mouseevent)
(x, y) = (mouseevent.x, mouseevent.y)
try:
trans = self.axes.transAxes.inverted()
(xaxes, yaxes) = trans.transform_point((x, y))
except ValueError:
return (False, {})
(l, b) = self.axes.transAxes.transform_point((0, 0))
(r, t) = self.axes.transAxes.transform_point((1, 1))
inaxis = ((yaxes >= 0) and (yaxes <= 1) and (((x < l) and (x > (l - self.pickradius))) or ((x > r) and (x < (r + self.pickradius)))))
return (inaxis, {})
|
'Return the label position (left or right)'
| def get_label_position(self):
| return self.label_position
|
'Set the label position (left or right)
ACCEPTS: [ \'left\' | \'right\' ]'
| def set_label_position(self, position):
| assert ((position == 'left') or (position == 'right'))
if (position == 'right'):
self.label.set_horizontalalignment('left')
else:
self.label.set_horizontalalignment('right')
self.label_position = position
|
'Update the label position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_label_position(self, bboxes, bboxes2):
| if (not self._autolabelpos):
return
(x, y) = self.label.get_position()
if (self.label_position == 'left'):
if (not len(bboxes)):
left = self.axes.bbox.xmin
else:
bbox = mtransforms.Bbox.union(bboxes)
left = bbox.x0
self.label.set_position(((left - ((self.LABELPAD * self.figure.dpi) / 72.0)), y))
else:
if (not len(bboxes2)):
right = self.axes.bbox.xmax
else:
bbox = mtransforms.Bbox.union(bboxes2)
right = bbox.x1
self.label.set_position(((right + ((self.LABELPAD * self.figure.dpi) / 72.0)), y))
|
'Update the offset_text position based on the sequence of bounding
boxes of all the ticklabels'
| def _update_offset_text_position(self, bboxes, bboxes2):
| (x, y) = self.offsetText.get_position()
top = self.axes.bbox.ymax
self.offsetText.set_position((x, (top + ((self.OFFSETTEXTPAD * self.figure.dpi) / 72.0))))
|
'Set the ticks position (left, right, both or default)
both sets the ticks to appear on both positions, but
does not change the tick labels.
default resets the tick positions to the default:
ticks on both positions, labels on the left.
ACCEPTS: [ \'left\' | \'right\' | \'both\' | \'default\' | \'none\' ]'
| def set_ticks_position(self, position):
| assert (position in ('left', 'right', 'both', 'default', 'none'))
ticks = list(self.get_major_ticks())
ticks.extend(self.get_minor_ticks())
if (position == 'right'):
self.set_offset_position('right')
for t in ticks:
t.tick1On = False
t.tick2On = True
t.label1On = False
t.label2On = True
elif (position == 'left'):
self.set_offset_position('left')
for t in ticks:
t.tick1On = True
t.tick2On = False
t.label1On = True
t.label2On = False
elif (position == 'default'):
self.set_offset_position('left')
for t in ticks:
t.tick1On = True
t.tick2On = True
t.label1On = True
t.label2On = False
elif (position == 'none'):
for t in ticks:
t.tick1On = False
t.tick2On = False
else:
self.set_offset_position('left')
for t in ticks:
t.tick1On = True
t.tick2On = True
|
'use ticks only on right'
| def tick_right(self):
| self.set_ticks_position('right')
|
'use ticks only on left'
| def tick_left(self):
| self.set_ticks_position('left')
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.