desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Called when wxPaintEvt is generated'
| def _onPaint(self, evt):
| DEBUG_MSG('_onPaint()', 1, self)
drawDC = wx.PaintDC(self)
if (not self._isDrawn):
self.draw(drawDC=drawDC)
else:
self.gui_repaint(drawDC=drawDC)
evt.Skip()
|
'Called when window is redrawn; since we are blitting the entire
image, we can leave this blank to suppress flicker.'
| def _onEraseBackground(self, evt):
| pass
|
'Called when wxEventSize is generated.
In this application we attempt to resize to fit the window, so it
is better to take the performance hit and redraw the whole window.'
| def _onSize(self, evt):
| DEBUG_MSG('_onSize()', 2, self)
(self._width, self._height) = self.GetClientSize()
self.bitmap = wx.EmptyBitmap(self._width, self._height)
self._isDrawn = False
if ((self._width <= 1) or (self._height <= 1)):
return
dpival = self.figure.dpi
winch = (self._width / dpival)
hinch = ... |
'a GUI idle event'
| def _onIdle(self, evt):
| evt.Skip()
FigureCanvasBase.idle_event(self, guiEvent=evt)
|
'Capture key press.'
| def _onKeyDown(self, evt):
| key = self._get_key(evt)
evt.Skip()
FigureCanvasBase.key_press_event(self, key, guiEvent=evt)
|
'Release key.'
| def _onKeyUp(self, evt):
| key = self._get_key(evt)
evt.Skip()
FigureCanvasBase.key_release_event(self, key, guiEvent=evt)
|
'Start measuring on an axis.'
| def _onRightButtonDown(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
evt.Skip()
self.CaptureMouse()
FigureCanvasBase.button_press_event(self, x, y, 3, guiEvent=evt)
|
'End measuring on an axis.'
| def _onRightButtonUp(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
evt.Skip()
if self.HasCapture():
self.ReleaseMouse()
FigureCanvasBase.button_release_event(self, x, y, 3, guiEvent=evt)
|
'Start measuring on an axis.'
| def _onLeftButtonDown(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
evt.Skip()
self.CaptureMouse()
FigureCanvasBase.button_press_event(self, x, y, 1, guiEvent=evt)
|
'End measuring on an axis.'
| def _onLeftButtonUp(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
evt.Skip()
if self.HasCapture():
self.ReleaseMouse()
FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt)
|
'Translate mouse wheel events into matplotlib events'
| def _onMouseWheel(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
delta = evt.GetWheelDelta()
rotation = evt.GetWheelRotation()
rate = evt.GetLinesPerAction()
step = ((rate * float(rotation)) / delta)
evt.Skip()
if (wx.Platform == '__WXMAC__'):
if (not hasattr(self, '_skipwheelevent')):
... |
'Start measuring on an axis.'
| def _onMotion(self, evt):
| x = evt.GetX()
y = (self.figure.bbox.height - evt.GetY())
evt.Skip()
FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=evt)
|
'Mouse has left the window.'
| def _onLeave(self, evt):
| evt.Skip()
FigureCanvasBase.leave_notify_event(self, guiEvent=evt)
|
'Mouse has entered the window.'
| def _onEnter(self, evt):
| FigureCanvasBase.enter_notify_event(self, guiEvent=evt)
|
'Override wxFrame::GetToolBar as we don\'t have managed toolbar'
| def GetToolBar(self):
| return self.toolbar
|
'Set the canvas size in pixels'
| def resize(self, width, height):
| self.canvas.SetInitialSize(wx.Size(width, height))
self.window.GetSizer().Fit(self.window)
|
'Handle menu button pressed.'
| def _onMenuButton(self, evt):
| (x, y) = self.GetPositionTuple()
(w, h) = self.GetSizeTuple()
self.PopupMenuXY(self._menu, x, ((y + h) - 4))
evt.Skip()
|
'Called when the \'select all axes\' menu item is selected.'
| def _handleSelectAllAxes(self, evt):
| if (len(self._axisId) == 0):
return
for i in range(len(self._axisId)):
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip()
|
'Called when the invert all menu item is selected'
| def _handleInvertAxesSelected(self, evt):
| if (len(self._axisId) == 0):
return
for i in range(len(self._axisId)):
if self._menu.IsChecked(self._axisId[i]):
self._menu.Check(self._axisId[i], False)
else:
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip(... |
'Called whenever one of the specific axis menu items is selected'
| def _onMenuItemSelected(self, evt):
| current = self._menu.IsChecked(evt.GetId())
if current:
new = False
else:
new = True
self._menu.Check(evt.GetId(), new)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip()
|
'Ensures that there are entries for max_axis axes in the menu
(selected by default).'
| def updateAxes(self, maxAxis):
| if (maxAxis > len(self._axisId)):
for i in range((len(self._axisId) + 1), (maxAxis + 1), 1):
menuId = wx.NewId()
self._axisId.append(menuId)
self._menu.Append(menuId, ('Axis %d' % i), ('Select axis %d' % i), True)
self._menu.Check(menuId, True)
... |
'Return a list of the selected axes.'
| def getActiveAxes(self):
| active = []
for i in range(len(self._axisId)):
if self._menu.IsChecked(self._axisId[i]):
active.append(i)
return active
|
'Update the list of selected axes in the menu button'
| def updateButtonText(self, lst):
| axis_txt = ''
for e in lst:
axis_txt += ('%d,' % (e + 1))
self.SetLabel(('Axes: %s' % axis_txt[:(-1)]))
|
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
| def draw_rubberband(self, event, x0, y0, x1, y1):
| canvas = self.canvas
dc = wx.ClientDC(canvas)
dc.SetLogicalFunction(wx.XOR)
wbrush = wx.Brush(wx.Colour(255, 255, 255), wx.TRANSPARENT)
wpen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID)
dc.SetBrush(wbrush)
dc.SetPen(wpen)
dc.ResetBoundingBox()
dc.BeginDrawing()
height = self.c... |
'figure is the Figure instance that the toolboar controls
win, if not None, is the wxWindow the Figure is embedded in'
| def __init__(self, canvas, can_kill=False):
| wx.ToolBar.__init__(self, canvas.GetParent(), (-1))
DEBUG_MSG('__init__()', 1, self)
self.canvas = canvas
self._lastControl = None
self._mouseOnButton = None
self._parent = canvas.GetParent()
self._NTB_BUTTON_HANDLER = {_NTB_X_PAN_LEFT: self.panx, _NTB_X_PAN_RIGHT: self.panx, _NTB_X_ZOOMIN: ... |
'Creates the \'menu\' - implemented as a button which opens a
pop-up menu since wxPython does not allow a menu as a control'
| def _create_menu(self):
| DEBUG_MSG('_create_menu()', 1, self)
self._menu = MenuButtonWx(self)
self.AddControl(self._menu)
self.AddSeparator()
|
'Creates the button controls, and links them to event handlers'
| def _create_controls(self, can_kill):
| DEBUG_MSG('_create_controls()', 1, self)
self.SetToolBitmapSize(wx.Size(16, 16))
self.AddSimpleTool(_NTB_X_PAN_LEFT, _load_bitmap('stock_left.xpm'), 'Left', 'Scroll left')
self.AddSimpleTool(_NTB_X_PAN_RIGHT, _load_bitmap('stock_right.xpm'), 'Right', 'Scroll right')
self.AddSimpleTool(_NTB_X_Z... |
'ind is a list of index numbers for the axes which are to be made active'
| def set_active(self, ind):
| DEBUG_MSG('set_active()', 1, self)
self._ind = ind
if (ind != None):
self._active = [self._axes[i] for i in self._ind]
else:
self._active = []
self._menu.updateButtonText(ind)
|
'Returns the identity of the last toolbar button pressed.'
| def get_last_control(self):
| return self._lastControl
|
'Update the toolbar menu - called when (e.g.) a new subplot or axes are added'
| def update(self):
| DEBUG_MSG('update()', 1, self)
self._axes = self.canvas.figure.get_axes()
self._menu.updateAxes(len(self._axes))
|
'A NULL event handler - does nothing whatsoever'
| def _do_nothing(self, d):
| pass
|
'id: object id of stream; len: an unused Reference object for the
length of the stream, or None (to use a memory buffer); file:
a PdfFile; extra: a dictionary of extra key-value pairs to
include in the stream header'
| def __init__(self, id, len, file, extra=None):
| self.id = id
self.len = len
self.pdfFile = file
self.file = file.fh
self.compressobj = None
if (extra is None):
self.extra = dict()
else:
self.extra = extra
self.pdfFile.recordXref(self.id)
if rcParams['pdf.compression']:
self.compressobj = zlib.compressobj(rc... |
'Finalize stream.'
| def end(self):
| self._flush()
if (self.len is None):
contents = self.file.getvalue()
self.len = len(contents)
self.file = self.pdfFile.fh
self._writeHeader()
self.file.write(contents)
self.file.write('\nendstream\nendobj\n')
else:
length = (self.file.tell() - self.pos... |
'Write some data on the stream.'
| def write(self, data):
| if (self.compressobj is None):
self.file.write(data)
else:
compressed = self.compressobj.compress(data)
self.file.write(compressed)
|
'Flush the compression object.'
| def _flush(self):
| if (self.compressobj is not None):
compressed = self.compressobj.flush()
self.file.write(compressed)
self.compressobj = None
|
'Select a font based on fontprop and return a name suitable for
Op.selectfont. If fontprop is a string, it will be interpreted
as the filename of the font.'
| def fontName(self, fontprop):
| if is_string_like(fontprop):
filename = fontprop
elif rcParams['pdf.use14corefonts']:
filename = findfont(fontprop, fontext='afm')
else:
filename = findfont(fontprop)
Fx = self.fontNames.get(filename)
if (Fx is None):
Fx = Name(('F%d' % self.nextFont))
self.fo... |
'Embed the TTF font from the named file into the document.'
| def embedTTF(self, filename, characters):
| font = FT2Font(str(filename))
fonttype = rcParams['pdf.fonttype']
def cvt(length, upe=font.units_per_EM, nearest=True):
'Convert font coordinates to PDF glyph coordinates'
value = ((length / upe) * 1000)
if nearest:
return round(value)
if (value ... |
'Return name of an ExtGState that sets alpha to the given value'
| def alphaState(self, alpha):
| state = self.alphaStates.get(alpha, None)
if (state is not None):
return state[0]
name = Name(('A%d' % self.nextAlphaState))
self.nextAlphaState += 1
self.alphaStates[alpha] = (name, {'Type': Name('ExtGState'), 'CA': alpha, 'ca': alpha})
return name
|
'Return name of an image XObject representing the given image.'
| def imageObject(self, image):
| pair = self.images.get(image, None)
if (pair is not None):
return pair[0]
name = Name(('I%d' % self.nextImage))
ob = self.reserveObject(('image %d' % self.nextImage))
self.nextImage += 1
self.images[image] = (name, ob)
return name
|
'Return name of a marker XObject representing the given path.'
| def markerObject(self, path, trans, fillp, lw):
| key = (path, trans, (fillp is not None), lw)
result = self.markers.get(key)
if (result is None):
name = Name(('M%d' % len(self.markers)))
ob = self.reserveObject(('marker %d' % len(self.markers)))
self.markers[key] = (name, ob, path, trans, fillp, lw)
else:
name = resu... |
'Reserve an ID for an indirect object.
The name is used for debugging in case we forget to print out
the object with writeObject.'
| def reserveObject(self, name=''):
| id = self.nextObject
self.nextObject += 1
self.xrefTable.append([None, 0, name])
return Reference(id)
|
'Write out the xref table.'
| def writeXref(self):
| self.startxref = self.fh.tell()
self.write(('xref\n0 %d\n' % self.nextObject))
i = 0
borken = False
for (offset, generation, name) in self.xrefTable:
if (offset is None):
print >>sys.stderr, ('No offset for object %d (%s)' % (i, name))
borken = True
... |
'Write out the PDF trailer.'
| def writeTrailer(self):
| self.write('trailer\n')
self.write(pdfRepr({'Size': self.nextObject, 'Root': self.rootObject, 'Info': self.infoObject}))
self.write(('\nstartxref\n%d\n%%%%EOF\n' % self.startxref))
|
'Keeps track of which characters are required from
each font.'
| def track_characters(self, font, s):
| if isinstance(font, (str, unicode)):
fname = font
else:
fname = font.fname
(realpath, stat_key) = get_realpath_and_stat(fname)
used_characters = self.used_characters.setdefault(stat_key, (realpath, set()))
used_characters[1].update([ord(x) for x in s])
|
'Set clip rectangle. Calls self.pop() and self.push().'
| def clip_cmd(self, cliprect, clippath):
| cmds = []
while (((self._cliprect, self._clippath) != (cliprect, clippath)) and (self.parent is not None)):
cmds.extend(self.pop())
if ((self._cliprect, self._clippath) != (cliprect, clippath)):
cmds.extend(self.push())
if (self._cliprect != cliprect):
cmds.extend([clipre... |
'Copy properties of other into self and return PDF commands
needed to transform self into other.'
| def delta(self, other):
| cmds = []
for (params, cmd) in self.commands:
different = False
for p in params:
ours = getattr(self, p)
theirs = getattr(other, p)
try:
different = bool((ours != theirs))
except ValueError:
ours = npy.asarray(ours)
... |
'Copy properties of other into self.'
| def copy_properties(self, other):
| GraphicsContextBase.copy_properties(self, other)
self._fillcolor = other._fillcolor
|
'Make sure every pushed graphics state is popped.'
| def finalize(self):
| cmds = []
while (self.parent is not None):
cmds.extend(self.pop())
return cmds
|
'Although postscript itself is dpi independent, we need to
imform the image code about a requested dpi to generate high
res images and them scale them before embeddin them'
| def __init__(self, width, height, pswriter, imagedpi=72):
| RendererBase.__init__(self)
self.width = width
self.height = height
self._pswriter = pswriter
if rcParams['text.usetex']:
self.textcnt = 0
self.psfrag = []
self.imagedpi = imagedpi
if rcParams['path.simplify']:
self.simplify = ((width * imagedpi), (height * imagedpi))... |
'Keeps track of which characters are required from
each font.'
| def track_characters(self, font, s):
| (realpath, stat_key) = get_realpath_and_stat(font.fname)
used_characters = self.used_characters.setdefault(stat_key, (realpath, set()))
used_characters[1].update([ord(x) for x in s])
|
'hatch can be one of:
/ - diagonal hatching
\ - back diagonal
| - vertical
- - horizontal
+ - crossed
X - crossed diagonal
letters can be combined, in which case all the specified
hatchings are done
if same letter repeats, it increases the density of hatching
in that direction'
| def set_hatch(self, hatch):
| hatches = {'horiz': 0, 'vert': 0, 'diag1': 0, 'diag2': 0}
for letter in hatch:
if (letter == '/'):
hatches['diag2'] += 1
elif (letter == '\\'):
hatches['diag1'] += 1
elif (letter == '|'):
hatches['vert'] += 1
elif (letter == '-'):
h... |
'return the canvas width and height in display coords'
| def get_canvas_width_height(self):
| return (self.width, self.height)
|
'get the width and height in display coords of the string s
with FontPropertry prop'
| def get_text_width_height_descent(self, s, prop, ismath):
| if rcParams['text.usetex']:
texmanager = self.get_texmanager()
fontsize = prop.get_size_in_points()
(l, b, r, t) = texmanager.get_ps_bbox(s, fontsize)
w = (r - l)
h = (t - b)
return (w, h, 0)
if ismath:
(width, height, descent, pswriter, used_characters) =... |
'return true if small y numbers are top for renderer'
| def flipy(self):
| return False
|
'Get the factor by which to magnify images passed to draw_image.
Allows a backend to have images at a different resolution to other
artists.'
| def get_image_magnification(self):
| return self.image_magnification
|
'Draw the Image instance into the current axes; x is the
distance in pixels from the left hand side of the canvas and y
is the distance from bottom
bbox is a matplotlib.transforms.BBox instance for clipping, or
None'
| def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
| im.flipud_out()
if im.is_grayscale:
(h, w, bits) = self._gray(im)
imagecmd = 'image'
else:
(h, w, bits) = self._rgb(im)
imagecmd = 'false 3 colorimage'
hexlines = '\n'.join(self._hex_lines(bits))
(xscale, yscale) = ((w / self.image_magnification), (h / self.imag... |
'Draws a Path instance using the given affine transform.'
| def draw_path(self, gc, path, transform, rgbFace=None):
| ps = self._convert_path(path, transform, self.simplify)
self._draw_ps(ps, gc, rgbFace)
|
'Draw the markers defined by path at each of the positions in x
and y. path coordinates are points, x and y coords will be
transformed by the transform'
| def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
| if debugPS:
self._pswriter.write('% draw_markers \n')
write = self._pswriter.write
if rgbFace:
if ((rgbFace[0] == rgbFace[1]) and (rgbFace[0] == rgbFace[2])):
ps_color = ('%1.3f setgray' % rgbFace[0])
else:
ps_color = ('%1.3f %1.3f %1.3f setr... |
'draw a Text instance'
| def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
| (w, h, bl) = self.get_text_width_height_descent(s, prop, ismath)
fontsize = prop.get_size_in_points()
corr = 0
pos = _nums_to_str((x - corr), y)
thetext = ('psmarker%d' % self.textcnt)
color = ('%1.3f,%1.3f,%1.3f' % gc.get_rgb()[:3])
fontcmd = {'sans-serif': '{\\sffamily %s}', 'monospace'... |
'draw a Text instance'
| def draw_text(self, gc, x, y, s, prop, angle, ismath):
| write = self._pswriter.write
if debugPS:
write('% text\n')
if (ismath == 'TeX'):
return self.tex(gc, x, y, s, prop, angle)
elif ismath:
return self.draw_mathtext(gc, x, y, s, prop, angle)
elif isinstance(s, unicode):
return self.draw_unicode(gc, x, y, s, prop, angl... |
'draw a unicode string. ps doesn\'t have unicode support, so
we have to do this the hard way'
| def draw_unicode(self, gc, x, y, s, prop, angle):
| if rcParams['ps.useafm']:
self.set_color(*gc.get_rgb())
font = self._get_font_afm(prop)
fontname = font.get_fontname()
fontsize = prop.get_size_in_points()
scale = (0.001 * fontsize)
thisx = 0
thisy = (font.get_str_bbox_and_descent(s)[4] * scale)
last_... |
'Draw the math text using matplotlib.mathtext'
| def draw_mathtext(self, gc, x, y, s, prop, angle):
| if debugPS:
self._pswriter.write('% mathtext\n')
(width, height, descent, pswriter, used_characters) = self.mathtext_parser.parse(s, 72, prop)
self.merge_used_characters(used_characters)
self.set_color(*gc.get_rgb())
thetext = pswriter.getvalue()
ps = ('gsave\n%(x)f %(y)f transl... |
'Emit the PostScript sniplet \'ps\' with all the attributes from \'gc\'
applied. \'ps\' must consist of PostScript commands to construct a path.
The fill and/or stroke kwargs can be set to False if the
\'ps\' string already includes filling and/or stroking, in
which case _draw_ps is just supplying properties and
clipp... | def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
| write = self._pswriter.write
if (debugPS and command):
write((('% ' + command) + '\n'))
mightstroke = ((gc.get_linewidth() > 0.0) and ((len(gc.get_rgb()) <= 3) or (gc.get_rgb()[3] != 0.0)))
stroke = (stroke and mightstroke)
fill = (fill and (rgbFace is not None) and ((len(rgbFace) <= 3) o... |
'Render the figure to hardcopy. Set the figure patch face and
edge colors. This is useful because some of the GUIs have a
gray figure face color background and you\'ll probably want to
override this on hardcopy
If outfile is a string, it is interpreted as a file name.
If the extension matches .ep* write encapsulated ... | def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w', orientation='portrait', isLandscape=False, papertype=None):
| isEPSF = (format == 'eps')
passed_in_file_object = False
if is_string_like(outfile):
title = outfile
tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
elif is_writable_file_like(outfile):
title = None
tmpfile = os.path.join(gettempdir(), md5(str(hash(outfile)... |
'If text.usetex is True in rc, a temporary pair of tex/eps files
are created to allow tex to manage the text layout via the PSFrags
package. These files are processed to yield the final ps or eps file.'
| def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor, orientation, isLandscape, papertype):
| isEPSF = (format == 'eps')
title = outfile
tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
fh = file(tmpfile, 'w')
self.figure.dpi = 72
(width, height) = self.figure.get_size_inches()
xo = 0
yo = 0
(l, b, w, h) = self.figure.bbox.bounds
llx = xo
lly = yo
ur... |
'Override by GTK backends to select a different renderer
Renderer should provide the methods:
set_pixmap ()
set_width_height ()
that are used by
_render_figure() / _pixmap_prepare()'
| def _renderer_init(self):
| self._renderer = RendererGDK(self, self.figure.dpi)
|
'Make sure _._pixmap is at least width, height,
create new pixmap if necessary'
| def _pixmap_prepare(self, width, height):
| if _debug:
print ('FigureCanvasGTK.%s' % fn_name())
create_pixmap = False
if (width > self._pixmap_width):
self._pixmap_width = max(int((self._pixmap_width * 1.1)), width)
create_pixmap = True
if (height > self._pixmap_height):
self._pixmap_height = max(int((self._pixmap_... |
'used by GTK and GTKcairo. GTKAgg overrides'
| def _render_figure(self, pixmap, width, height):
| self._renderer.set_width_height(width, height)
self.figure.draw(self._renderer)
|
'Expose_event for all GTK backends. Should not be overridden.'
| def expose_event(self, widget, event):
| if _debug:
print ('FigureCanvasGTK.%s' % fn_name())
if GTK_WIDGET_DRAWABLE(self):
if self._need_redraw:
(x, y, w, h) = self.allocation
self._pixmap_prepare(w, h)
self._render_figure(self._pixmap, w, h)
self._need_redraw = False
(x, y, w, h)... |
'set the canvas size in pixels'
| def resize(self, width, height):
| self.window.resize(width, height)
|
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
| def draw_rubberband(self, event, x0, y0, x1, y1):
| drawable = self.canvas.window
if (drawable is None):
return
gc = drawable.new_gc()
height = self.canvas.figure.bbox.height
y1 = (height - y1)
y0 = (height - y0)
w = abs((x1 - x0))
h = abs((y1 - y0))
rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)]
try:
... |
'figManager is the FigureManagerGTK instance that contains the
toolbar, with attributes figure, window and drawingArea'
| def __init__(self, canvas, window):
| gtk.Toolbar.__init__(self)
self.canvas = canvas
self.win = window
self.set_style(gtk.TOOLBAR_ICONS)
if (gtk.pygtk_version >= (2, 4, 0)):
self._create_toolitems_2_4()
self.update = self._update_2_4
self.fileselect = FileChooserDialog(title='Save the figure', parent=self.... |
'panx in direction'
| def panx(self, button, direction):
| for a in self._active:
a.xaxis.pan(direction)
self.canvas.draw()
return True
|
'pany in direction'
| def pany(self, button, direction):
| for a in self._active:
a.yaxis.pan(direction)
self.canvas.draw()
return True
|
'zoomx in direction'
| def zoomx(self, button, direction):
| for a in self._active:
a.xaxis.zoom(direction)
self.canvas.draw()
return True
|
'zoomy in direction'
| def zoomy(self, button, direction):
| for a in self._active:
a.yaxis.zoom(direction)
self.canvas.draw()
return True
|
'populate the combo box'
| def show(self):
| self._updateson = False
cbox = self.cbox_lineprops
for i in range((self._lastcnt - 1), (-1), (-1)):
cbox.remove_text(i)
for line in self.lines:
cbox.append_text(line.get_label())
cbox.set_active(0)
self._updateson = True
self._lastcnt = len(self.lines)
self.dlg.show()
|
'get the active line'
| def get_active_line(self):
| ind = self.cbox_lineprops.get_active()
line = self.lines[ind]
return line
|
'get the active lineinestyle'
| def get_active_linestyle(self):
| ind = self.cbox_linestyles.get_active()
ls = self.linestyles[ind]
return ls
|
'get the active lineinestyle'
| def get_active_marker(self):
| ind = self.cbox_markers.get_active()
m = self.markers[ind]
return m
|
'update the active line props from the widgets'
| def _update(self):
| if ((not self._inited) or (not self._updateson)):
return
line = self.get_active_line()
ls = self.get_active_linestyle()
marker = self.get_active_marker()
line.set_linestyle(ls)
line.set_marker(marker)
button = self.wtree.get_widget('colorbutton_linestyle')
color = button.get_colo... |
'update the widgets from the active line'
| def on_combobox_lineprops_changed(self, item):
| if (not self._inited):
return
self._updateson = False
line = self.get_active_line()
ls = line.get_linestyle()
if (ls is None):
ls = 'None'
self.cbox_linestyles.set_active(self.linestyled[ls])
marker = line.get_marker()
if (marker is None):
marker = 'None'
self... |
'called colorbutton marker clicked'
| def on_colorbutton_markerface_color_set(self, button):
| self._update()
|
'width: The width of the canvas in logical units
height: The height of the canvas in logical units
dpi: The dpi of the canvas
vector_renderer: An instance of a subclass of RendererBase
that will be used for the vector drawing.
raster_renderer_class: The renderer class to use for the
raster drawing. If not provided, th... | def __init__(self, width, height, dpi, vector_renderer, raster_renderer_class=None):
| if (raster_renderer_class is None):
raster_renderer_class = RendererAgg
self._raster_renderer_class = raster_renderer_class
self._width = width
self._height = height
self.dpi = dpi
assert (not vector_renderer.option_image_nocomposite())
self._vector_renderer = vector_renderer
sel... |
'Enter "raster" mode. All subsequent drawing commands (until
stop_rasterizing is called) will be drawn with the raster
backend.
If start_rasterizing is called multiple times before
stop_rasterizing is called, this method has no effect.'
| def start_rasterizing(self):
| if (self._rasterizing == 0):
self._raster_renderer = self._raster_renderer_class((self._width * self.dpi), (self._height * self.dpi), self.dpi)
self._set_current_renderer(self._raster_renderer)
self._rasterizing += 1
|
'Exit "raster" mode. All of the drawing that was done since
the last start_rasterizing command will be copied to the
vector backend by calling draw_image.
If stop_rasterizing is called multiple times before
start_rasterizing is called, this method has no effect.'
| def stop_rasterizing(self):
| self._rasterizing -= 1
if (self._rasterizing == 0):
self._set_current_renderer(self._vector_renderer)
(width, height) = ((self._width * self.dpi), (self._height * self.dpi))
(buffer, bounds) = self._raster_renderer.tostring_rgba_minimized()
(l, b, w, h) = bounds
if ((w > ... |
'Draw the figure using the renderer'
| def draw(self):
| renderer = RendererTemplate(self.figure.dpi)
self.figure.draw(renderer)
|
'Write out format foo. The dpi, facecolor and edgecolor are restored
to their original values after this call, so you don\'t need to
save and restore them.'
| def print_foo(self, filename, *args, **kwargs):
| pass
|
'return the style string.
style is generated from the GraphicsContext, rgbFace and clippath'
| def _get_style(self, gc, rgbFace):
| if (rgbFace is None):
fill = 'none'
else:
fill = rgb2hex(rgbFace[:3])
(offset, seq) = gc.get_dashes()
if (seq is None):
dashes = ''
else:
dashes = ('stroke-dasharray: %s; stroke-dashoffset: %f;' % (','.join([('%f' % val) for val in seq]), offset))
linewid... |
'if svg.image_noscale is True, compositing multiple images into one is prohibited'
| def option_image_nocomposite(self):
| return rcParams['svg.image_noscale']
|
'Draw math text using matplotlib.mathtext'
| def _draw_mathtext(self, gc, x, y, s, prop, angle):
| (width, height, descent, svg_elements, used_characters) = self.mathtext_parser.parse(s, 72, prop)
svg_glyphs = svg_elements.svg_glyphs
svg_rects = svg_elements.svg_rects
color = rgb2hex(gc.get_rgb()[:3])
write = self._svgwriter.write
style = ('fill: %s' % color)
if rcParams['svg.embed_cha... |
'Initialize the renderer with a gd image instance'
| def __init__(self, outfile, width, height, dpi):
| self.outfile = outfile
self._cached = {}
self._fontHandle = {}
self.lastHandle = {'font': (-1), 'pen': (-1), 'brush': (-1)}
self.emf = pyemf.EMF(width, height, dpi, 'in')
self.width = int((width * dpi))
self.height = int((height * dpi))
self.dpi = dpi
self.pointstodpi = (dpi / 72.0)
... |
'Draw an arc using GraphicsContext instance gcEdge, centered at x,y,
with width and height and angles from 0.0 to 360.0
0 degrees is at 3-o\'clock
positive angles are anti-clockwise
If the color rgbFace is not None, fill the arc with it.'
| def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2, rotation):
| if debugPrint:
print ('draw_arc: (%f,%f) angles=(%f,%f) w,h=(%f,%f)' % (x, y, angle1, angle2, width, height))
pen = self.select_pen(gcEdge)
brush = self.select_brush(rgbFace)
hw = (width / 2)
hh = (height / 2)
x1 = int((x - (width / 2)))
y1 = int((y - (height / 2)))
if b... |
'Draw the Image instance into the current axes; x is the
distance in pixels from the left hand side of the canvas. y is
the distance from the origin. That is, if origin is upper, y
is the distance from top. If origin is lower, y is the
distance from bottom
bbox is a matplotlib.transforms.BBox instance for clipping, o... | def draw_image(self, x, y, im, bbox):
| pass
|
'Draw a single line from x1,y1 to x2,y2'
| def draw_line(self, gc, x1, y1, x2, y2):
| if debugPrint:
print ('draw_line: (%f,%f) - (%f,%f)' % (x1, y1, x2, y2))
if self.select_pen(gc):
self.emf.Polyline([(long(x1), long((self.height - y1))), (long(x2), long((self.height - y2)))])
elif debugPrint:
print ('draw_line: optimizing away (%f,%f) - (%f,%... |
'x and y are equal length arrays, draw lines connecting each
point in x, y'
| def draw_lines(self, gc, x, y):
| if debugPrint:
print ('draw_lines: %d points' % len(str(x)))
if self.select_pen(gc):
points = [(long(x[i]), long((self.height - y[i]))) for i in range(len(x))]
self.emf.Polyline(points)
|
'Draw a single point at x,y
Where \'point\' is a device-unit point (or pixel), not a matplotlib point'
| def draw_point(self, gc, x, y):
| if debugPrint:
print ('draw_point: (%f,%f)' % (x, y))
pen = EMFPen(self.emf, gc)
self.emf.SetPixel(long(x), long((self.height - y)), (pen.r, pen.g, pen.b))
|
'Draw a polygon using the GraphicsContext instance gc.
points is a len vertices tuple, each element
giving the x,y coords a vertex
If the color rgbFace is not None, fill the polygon with it'
| def draw_polygon(self, gcEdge, rgbFace, points):
| if debugPrint:
print ('draw_polygon: %d points' % len(points))
pen = self.select_pen(gcEdge)
brush = self.select_brush(rgbFace)
if (pen or brush):
points = [(long(x), long((self.height - y))) for (x, y) in points]
self.emf.Polygon(points)
else:
points = [(long(x... |
'Draw a non-filled rectangle using the GraphicsContext instance gcEdge,
with lower left at x,y with width and height.
If rgbFace is not None, fill the rectangle with it.'
| def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
| if debugPrint:
print ('draw_rectangle: (%f,%f) w=%f,h=%f' % (x, y, width, height))
pen = self.select_pen(gcEdge)
brush = self.select_brush(rgbFace)
if (pen or brush):
self.emf.Rectangle(int(x), int((self.height - y)), (int(x) + int(width)), (int((self.height - y)) - int(height)))
... |
'Draw the text.Text instance s at x,y (display coords) with font
properties instance prop at angle in degrees, using GraphicsContext gc
**backend implementers note**
When you are trying to determine if you have gotten your bounding box
right (which is what enables the text layout/alignment to work
properly), it helps t... | def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
| if debugText:
print ("draw_text: (%f,%f) %d degrees: '%s'" % (x, y, angle, s))
if ismath:
self.draw_math_text(gc, x, y, s, prop, angle)
else:
self.draw_plain_text(gc, x, y, s, prop, angle)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.