<s> """<STR_LIT>""" <EOL> import wx <EOL> import os . path <EOL> import weakref <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> import numpy as np <EOL> from matplotlib . axes import _process_plot_var_args <EOL> from matplotlib . backends . backend_agg import RendererAgg <EOL> from matplotlib . backends . backend_wxagg import FigureCanvasWxAgg <EOL> from matplotlib . figure import Figure <EOL> from matplotlib . font_manager import FontProperties <EOL> from matplotlib . transforms import Bbox <EOL> __version__ = '<STR_LIT>' <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> POSTSCRIPT_PRINTING_COMMAND = '<STR_LIT>' <EOL> MATPLOTLIB_0_98_3 = '<STR_LIT>' <= matplotlib . __version__ <EOL> def invert_point ( x , y , transform ) : <EOL> """<STR_LIT>""" <EOL> return transform . inverted ( ) . transform_point ( ( x , y ) ) <EOL> def find_axes ( canvas , x , y ) : <EOL> """<STR_LIT>""" <EOL> evt = matplotlib . backend_bases . MouseEvent ( '<STR_LIT>' , canvas , x , y ) <EOL> axes = None <EOL> for a in canvas . get_figure ( ) . get_axes ( ) : <EOL> if a . in_axes ( evt ) : <EOL> if axes is None : <EOL> axes = a <EOL> else : <EOL> return None , None , None <EOL> if axes is None : <EOL> return None , None , None <EOL> xdata , ydata = invert_point ( x , y , axes . transData ) <EOL> return axes , xdata , ydata <EOL> def get_bbox_lims ( bbox ) : <EOL> """<STR_LIT>""" <EOL> p0 = bbox . min <EOL> p1 = bbox . max <EOL> return ( p0 [ <NUM_LIT:0> ] , p1 [ <NUM_LIT:0> ] ) , ( p0 [ <NUM_LIT:1> ] , p1 [ <NUM_LIT:1> ] ) <EOL> def find_selected_axes ( canvas , x1 , y1 , x2 , y2 ) : <EOL> """<STR_LIT>""" <EOL> axes = None <EOL> bbox = Bbox . from_extents ( x1 , y1 , x2 , y2 ) <EOL> for a in canvas . get_figure ( ) . get_axes ( ) : <EOL> if bbox . overlaps ( a . bbox ) : <EOL> if axes is None : <EOL> axes = a <EOL> else : <EOL> return None , None , None <EOL> if axes is None : <EOL> return None , None , None <EOL> x1 , y1 , x2 , y2 = limit_selection ( bbox , axes ) <EOL> xrange , yrange = get_bbox_lims ( <EOL> Bbox . from_extents ( x1 , y1 , x2 , y2 ) . inverse_transformed ( axes . transData ) ) <EOL> return axes , xrange , yrange <EOL> def limit_selection ( bbox , axes ) : <EOL> """<STR_LIT>""" <EOL> bxr , byr = get_bbox_lims ( bbox ) <EOL> axr , ayr = get_bbox_lims ( axes . bbox ) <EOL> xmin = max ( bxr [ <NUM_LIT:0> ] , axr [ <NUM_LIT:0> ] ) <EOL> xmax = min ( bxr [ <NUM_LIT:1> ] , axr [ <NUM_LIT:1> ] ) <EOL> ymin = max ( byr [ <NUM_LIT:0> ] , ayr [ <NUM_LIT:0> ] ) <EOL> ymax = min ( byr [ <NUM_LIT:1> ] , ayr [ <NUM_LIT:1> ] ) <EOL> return xmin , ymin , xmax , ymax <EOL> def format_coord ( axes , xdata , ydata ) : <EOL> """<STR_LIT>""" <EOL> if xdata is None or ydata is None : <EOL> return '<STR_LIT>' <EOL> return axes . format_coord ( xdata , ydata ) <EOL> def toplevel_parent_of_window ( window ) : <EOL> """<STR_LIT>""" <EOL> topwin = window <EOL> while not isinstance ( topwin , wx . TopLevelWindow ) : <EOL> topwin = topwin . GetParent ( ) <EOL> return topwin <EOL> class AxesLimits : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , autoscaleUnzoom ) : <EOL> self . autoscaleUnzoom = autoscaleUnzoom <EOL> self . history = weakref . WeakKeyDictionary ( ) <EOL> def setAutoscaleUnzoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . limits . setAutoscaleUnzoom ( state ) <EOL> def _get_history ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> return self . history . setdefault ( axes , [ ] ) <EOL> def zoomed ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> return not ( not self . _get_history ( axes ) ) <EOL> def set ( self , axes , xrange , yrange ) : <EOL> """<STR_LIT>""" <EOL> if not axes . can_zoom ( ) : <EOL> return False <EOL> oldRange = tuple ( axes . get_xlim ( ) ) , tuple ( axes . get_ylim ( ) ) <EOL> history = self . _get_history ( axes ) <EOL> history . append ( oldRange ) <EOL> axes . set_xlim ( xrange ) <EOL> axes . set_ylim ( yrange ) <EOL> return True <EOL> def restore ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> history = self . _get_history ( axes ) <EOL> if not history : <EOL> return False <EOL> xrange , yrange = history . pop ( ) <EOL> if self . autoscaleUnzoom and not len ( history ) : <EOL> axes . autoscale_view ( ) <EOL> else : <EOL> axes . set_xlim ( xrange ) <EOL> axes . set_ylim ( yrange ) <EOL> return True <EOL> class PlotPanelDirector : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view , zoom = True , selection = True , rightClickUnzoom = True , <EOL> autoscaleUnzoom = True ) : <EOL> """<STR_LIT>""" <EOL> self . view = view <EOL> self . zoomEnabled = zoom <EOL> self . selectionEnabled = selection <EOL> self . rightClickUnzoom = rightClickUnzoom <EOL> self . limits = AxesLimits ( autoscaleUnzoom ) <EOL> self . leftButtonPoint = None <EOL> def setSelection ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . selectionEnabled = state <EOL> def setZoomEnabled ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . zoomEnabled = state <EOL> def setAutoscaleUnzoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . limits . setAutoscaleUnzoom ( state ) <EOL> def setRightClickUnzoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . rightClickUnzoom = state <EOL> def canDraw ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . leftButtonPoint is None <EOL> def zoomed ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> return self . limits . zoomed ( axes ) <EOL> def keyDown ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> evt . Skip ( ) <EOL> def keyUp ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> evt . Skip ( ) <EOL> def leftButtonDown ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> self . leftButtonPoint = ( x , y ) <EOL> view = self . view <EOL> axes , xdata , ydata = find_axes ( view , x , y ) <EOL> if axes is not None and self . selectionEnabled and axes . can_zoom ( ) : <EOL> view . cursor . setCross ( ) <EOL> view . crosshairs . clear ( ) <EOL> def leftButtonUp ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> if self . leftButtonPoint is None : <EOL> return <EOL> view = self . view <EOL> axes , xdata , ydata = find_axes ( view , x , y ) <EOL> x0 , y0 = self . leftButtonPoint <EOL> self . leftButtonPoint = None <EOL> view . rubberband . clear ( ) <EOL> if x0 == x : <EOL> if y0 == y and axes is not None : <EOL> view . notify_point ( axes , x , y ) <EOL> view . crosshairs . set ( x , y ) <EOL> return <EOL> elif y0 == y : <EOL> return <EOL> xdata = ydata = None <EOL> axes , xrange , yrange = find_selected_axes ( view , x0 , y0 , x , y ) <EOL> if axes is not None : <EOL> xdata , ydata = invert_point ( x , y , axes . transData ) <EOL> if self . zoomEnabled : <EOL> if self . limits . set ( axes , xrange , yrange ) : <EOL> self . view . draw ( ) <EOL> else : <EOL> bbox = Bbox . from_extents ( x0 , y0 , x , y ) <EOL> x1 , y1 , x2 , y2 = limit_selection ( bbox , axes ) <EOL> self . view . notify_selection ( axes , x1 , y1 , x2 , y2 ) <EOL> if axes is None : <EOL> view . cursor . setNormal ( ) <EOL> elif not axes . can_zoom ( ) : <EOL> view . cursor . setNormal ( ) <EOL> view . location . set ( format_coord ( axes , xdata , ydata ) ) <EOL> else : <EOL> view . crosshairs . set ( x , y ) <EOL> view . location . set ( format_coord ( axes , xdata , ydata ) ) <EOL> def rightButtonDown ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> evt . Skip ( ) <EOL> def rightButtonUp ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> axes , xdata , ydata = find_axes ( view , x , y ) <EOL> if ( axes is not None and self . zoomEnabled and self . rightClickUnzoom <EOL> and self . limits . restore ( axes ) ) : <EOL> view . crosshairs . clear ( ) <EOL> view . draw ( ) <EOL> view . crosshairs . set ( x , y ) <EOL> def mouseMotion ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> axes , xdata , ydata = find_axes ( view , x , y ) <EOL> if self . leftButtonPoint is not None : <EOL> self . selectionMouseMotion ( evt , x , y , axes , xdata , ydata ) <EOL> else : <EOL> if axes is None : <EOL> self . canvasMouseMotion ( evt , x , y ) <EOL> elif not axes . can_zoom ( ) : <EOL> self . unzoomableAxesMouseMotion ( evt , x , y , axes , xdata , ydata ) <EOL> else : <EOL> self . axesMouseMotion ( evt , x , y , axes , xdata , ydata ) <EOL> def selectionMouseMotion ( self , evt , x , y , axes , xdata , ydata ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> x0 , y0 = self . leftButtonPoint <EOL> view . rubberband . set ( x0 , y0 , x , y ) <EOL> if axes is None : <EOL> view . location . clear ( ) <EOL> else : <EOL> view . location . set ( format_coord ( axes , xdata , ydata ) ) <EOL> def canvasMouseMotion ( self , evt , x , y ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> view . cursor . setNormal ( ) <EOL> view . crosshairs . clear ( ) <EOL> view . location . clear ( ) <EOL> def axesMouseMotion ( self , evt , x , y , axes , xdata , ydata ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> view . cursor . setCross ( ) <EOL> view . crosshairs . set ( x , y ) <EOL> view . location . set ( format_coord ( axes , xdata , ydata ) ) <EOL> def unzoomableAxesMouseMotion ( self , evt , x , y , axes , xdata , ydata ) : <EOL> """<STR_LIT>""" <EOL> view = self . view <EOL> view . cursor . setNormal ( ) <EOL> view . location . set ( format_coord ( axes , xdata , ydata ) ) <EOL> class Painter : <EOL> """<STR_LIT>""" <EOL> PEN = wx . BLACK_PEN <EOL> BRUSH = wx . TRANSPARENT_BRUSH <EOL> FUNCTION = wx . COPY <EOL> FONT = wx . NORMAL_FONT <EOL> TEXT_FOREGROUND = wx . BLACK <EOL> TEXT_BACKGROUND = wx . WHITE <EOL> def __init__ ( self , view , enabled = True ) : <EOL> """<STR_LIT>""" <EOL> self . view = view <EOL> self . lastValue = None <EOL> self . enabled = enabled <EOL> def setEnabled ( self , state ) : <EOL> """<STR_LIT>""" <EOL> oldState , self . enabled = self . enabled , state <EOL> if oldState and not self . enabled : <EOL> self . clear ( ) <EOL> def set ( self , * value ) : <EOL> """<STR_LIT>""" <EOL> if self . enabled : <EOL> value = self . formatValue ( value ) <EOL> self . _paint ( value , None ) <EOL> def redraw ( self , dc = None ) : <EOL> """<STR_LIT>""" <EOL> value = self . lastValue <EOL> self . lastValue = None <EOL> self . _paint ( value , dc ) <EOL> def clear ( self , dc = None ) : <EOL> """<STR_LIT>""" <EOL> if self . lastValue is not None : <EOL> self . _paint ( None , dc ) <EOL> def _paint ( self , value , dc ) : <EOL> """<STR_LIT>""" <EOL> if dc is None : <EOL> dc = wx . ClientDC ( self . view ) <EOL> dc . SetPen ( self . PEN ) <EOL> dc . SetBrush ( self . BRUSH ) <EOL> dc . SetFont ( self . FONT ) <EOL> dc . SetTextForeground ( self . TEXT_FOREGROUND ) <EOL> dc . SetTextBackground ( self . TEXT_BACKGROUND ) <EOL> dc . SetLogicalFunction ( self . FUNCTION ) <EOL> dc . BeginDrawing ( ) <EOL> if self . lastValue is not None : <EOL> self . clearValue ( dc , self . lastValue ) <EOL> self . lastValue = None <EOL> if value is not None : <EOL> self . drawValue ( dc , value ) <EOL> self . lastValue = value <EOL> dc . EndDrawing ( ) <EOL> def formatValue ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value <EOL> def drawValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def clearValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class LocationPainter ( Painter ) : <EOL> """<STR_LIT>""" <EOL> PADDING = <NUM_LIT:2> <EOL> PEN = wx . WHITE_PEN <EOL> BRUSH = wx . WHITE_BRUSH <EOL> def formatValue ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value [ <NUM_LIT:0> ] <EOL> def get_XYWH ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> height = dc . GetSize ( ) [ <NUM_LIT:1> ] <EOL> w , h = dc . GetTextExtent ( value ) <EOL> x = self . PADDING <EOL> y = int ( height - ( h + self . PADDING ) ) <EOL> return x , y , w , h <EOL> def drawValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> x , y , w , h = self . get_XYWH ( dc , value ) <EOL> dc . DrawText ( value , x , y ) <EOL> def clearValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> x , y , w , h = self . get_XYWH ( dc , value ) <EOL> dc . DrawRectangle ( x , y , w , h ) <EOL> class CrosshairPainter ( Painter ) : <EOL> """<STR_LIT>""" <EOL> PEN = wx . WHITE_PEN <EOL> FUNCTION = wx . XOR <EOL> def formatValue ( self , value ) : <EOL> """<STR_LIT>""" <EOL> x , y = value <EOL> return int ( x ) , int ( self . view . get_figure ( ) . bbox . height - y ) <EOL> def drawValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> dc . CrossHair ( * value ) <EOL> def clearValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> dc . CrossHair ( * value ) <EOL> class RubberbandPainter ( Painter ) : <EOL> """<STR_LIT>""" <EOL> PEN = wx . WHITE_PEN <EOL> FUNCTION = wx . XOR <EOL> def formatValue ( self , value ) : <EOL> """<STR_LIT>""" <EOL> x1 , y1 , x2 , y2 = value <EOL> height = self . view . get_figure ( ) . bbox . height <EOL> y1 = height - y1 <EOL> y2 = height - y2 <EOL> if x2 < x1 : x1 , x2 = x2 , x1 <EOL> if y2 < y1 : y1 , y2 = y2 , y1 <EOL> return [ int ( z ) for z in ( x1 , y1 , x2 - x1 , y2 - y1 ) ] <EOL> def drawValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> dc . DrawRectangle ( * value ) <EOL> def clearValue ( self , dc , value ) : <EOL> """<STR_LIT>""" <EOL> dc . DrawRectangle ( * value ) <EOL> class CursorChanger : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view , enabled = True ) : <EOL> """<STR_LIT>""" <EOL> self . view = view <EOL> self . cursor = wx . CURSOR_DEFAULT <EOL> self . enabled = enabled <EOL> def setEnabled ( self , state ) : <EOL> """<STR_LIT>""" <EOL> oldState , self . enabled = self . enabled , state <EOL> if oldState and not self . enabled and self . cursor != wx . CURSOR_DEFAULT : <EOL> self . cursor = wx . CURSOR_DEFAULT <EOL> self . view . SetCursor ( wx . STANDARD_CURSOR ) <EOL> def setNormal ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cursor != wx . CURSOR_DEFAULT and self . enabled : <EOL> self . cursor = wx . CURSOR_DEFAULT <EOL> self . view . SetCursor ( wx . STANDARD_CURSOR ) <EOL> def setCross ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cursor != wx . CURSOR_CROSS and self . enabled : <EOL> self . cursor = wx . CURSOR_CROSS <EOL> self . view . SetCursor ( wx . CROSS_CURSOR ) <EOL> PS_DPI_HIGH_QUALITY = <NUM_LIT> <EOL> PS_DPI_MEDIUM_QUALITY = <NUM_LIT> <EOL> PS_DPI_LOW_QUALITY = <NUM_LIT> <EOL> PS_DPI_DRAFT_QUALITY = <NUM_LIT> <EOL> def update_postscript_resolution ( printData ) : <EOL> """<STR_LIT>""" <EOL> if not callable ( getattr ( wx , '<STR_LIT>' , None ) ) : <EOL> return <EOL> quality = printData . GetQuality ( ) <EOL> if quality > <NUM_LIT:0> : <EOL> dpi = quality <EOL> elif quality == wx . PRINT_QUALITY_HIGH : <EOL> dpi = PS_DPI_HIGH_QUALITY <EOL> elif quality == wx . PRINT_QUALITY_MEDIUM : <EOL> dpi = PS_DPI_MEDIUM_QUALITY <EOL> elif quality == wx . PRINT_QUALITY_LOW : <EOL> dpi = PS_DPI_LOW_QUALITY <EOL> elif quality == wx . PRINT_QUALITY_DRAFT : <EOL> dpi = PS_DPI_DRAFT_QUALITY <EOL> else : <EOL> dpi = PS_DPI_HIGH_QUALITY <EOL> wx . PostScriptDC_SetResolution ( dpi ) <EOL> class FigurePrinter : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view , printData = None ) : <EOL> """<STR_LIT>""" <EOL> self . view = view <EOL> if printData is None : <EOL> printData = wx . PrintData ( ) <EOL> self . setPrintData ( printData ) <EOL> def getPrintData ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . pData <EOL> def setPrintData ( self , printData ) : <EOL> """<STR_LIT>""" <EOL> self . pData = printData <EOL> update_postscript_resolution ( self . pData ) <EOL> def pageSetup ( self ) : <EOL> dlg = wx . PrintDialog ( self . view ) <EOL> pdData = dlg . GetPrintDialogData ( ) <EOL> pdData . SetPrintData ( self . pData ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> self . setPrintData ( pdData . GetPrintData ( ) ) <EOL> dlg . Destroy ( ) <EOL> def previewFigure ( self , figure , title = None ) : <EOL> """<STR_LIT>""" <EOL> topwin = toplevel_parent_of_window ( self . view ) <EOL> fpo = FigurePrintout ( figure , title ) <EOL> fpo4p = FigurePrintout ( figure , title ) <EOL> preview = wx . PrintPreview ( fpo , fpo4p , self . pData ) <EOL> frame = wx . PreviewFrame ( preview , topwin , '<STR_LIT>' ) <EOL> if self . pData . GetOrientation ( ) == wx . PORTRAIT : <EOL> frame . SetSize ( wx . Size ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> else : <EOL> frame . SetSize ( wx . Size ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> frame . Initialize ( ) <EOL> frame . Show ( True ) <EOL> def printFigure ( self , figure , title = None ) : <EOL> """<STR_LIT>""" <EOL> pdData = wx . PrintDialogData ( ) <EOL> pdData . SetPrintData ( self . pData ) <EOL> printer = wx . Printer ( pdData ) <EOL> fpo = FigurePrintout ( figure , title ) <EOL> if printer . Print ( self . view , fpo , True ) : <EOL> self . setPrintData ( pdData . GetPrintData ( ) ) <EOL> class FigurePrintout ( wx . Printout ) : <EOL> """<STR_LIT>""" <EOL> ASPECT_RECTANGULAR = <NUM_LIT:1> <EOL> ASPECT_SQUARE = <NUM_LIT:2> <EOL> def __init__ ( self , figure , title = None , size = None , aspectRatio = None ) : <EOL> """<STR_LIT>""" <EOL> self . figure = figure <EOL> figTitle = figure . gca ( ) . title . get_text ( ) <EOL> if not figTitle : <EOL> figTitle = title or '<STR_LIT>' <EOL> if size is None : <EOL> size = <NUM_LIT:100> <EOL> elif size < <NUM_LIT:1> or size > <NUM_LIT:100> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . size = size <EOL> if aspectRatio is None : <EOL> aspectRatio = self . ASPECT_RECTANGULAR <EOL> elif ( aspectRatio != self . ASPECT_RECTANGULAR <EOL> and aspectRatio != self . ASPECT_SQUARE ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . aspectRatio = aspectRatio <EOL> wx . Printout . __init__ ( self , figTitle ) <EOL> def GetPageInfo ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def HasPage ( self , pageNumber ) : <EOL> """<STR_LIT>""" <EOL> return pageNumber == <NUM_LIT:1> <EOL> def OnPrintPage ( self , pageNumber ) : <EOL> """<STR_LIT>""" <EOL> imgPercent = max ( <NUM_LIT:1> , min ( <NUM_LIT:100> , self . size ) ) / <NUM_LIT> <EOL> if self . aspectRatio == self . ASPECT_RECTANGULAR : <EOL> aspectRatio = <NUM_LIT> <EOL> elif self . aspectRatio == self . ASPECT_SQUARE : <EOL> aspectRatio = <NUM_LIT:1.0> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> dc = self . GetDC ( ) <EOL> wPPI_P , hPPI_P = [ float ( x ) for x in self . GetPPIPrinter ( ) ] <EOL> PPI_P = ( wPPI_P + hPPI_P ) / <NUM_LIT> <EOL> if self . IsPreview ( ) : <EOL> wPPI , hPPI = [ float ( x ) for x in self . GetPPIScreen ( ) ] <EOL> else : <EOL> wPPI , hPPI = wPPI_P , hPPI_P <EOL> PPI = ( wPPI + hPPI ) / <NUM_LIT> <EOL> wPg_Px , hPg_Px = [ float ( x ) for x in self . GetPageSizePixels ( ) ] <EOL> wDev_Px , hDev_Px = [ float ( x ) for x in self . GetDC ( ) . GetSize ( ) ] <EOL> wPg = wPg_Px / PPI_P <EOL> hPg = hPg_Px / PPI_P <EOL> wM = <NUM_LIT> <EOL> hM = <NUM_LIT> <EOL> wArea = wPg - <NUM_LIT:2> * wM <EOL> hArea = hPg - <NUM_LIT:2> * hM <EOL> max_hFig = wArea / aspectRatio <EOL> hFig = min ( imgPercent * hArea , max_hFig ) <EOL> wFig = aspectRatio * hFig <EOL> S = ( ( wDev_Px / PPI ) / wPg + ( hDev_Px / PPI ) / hPg ) / <NUM_LIT> <EOL> wFig_S = S * wFig <EOL> hFig_S = S * hFig <EOL> wM_S = S * wM <EOL> hM_S = S * hM <EOL> wFig_Dx = int ( S * PPI * wFig ) <EOL> hFig_Dx = int ( S * PPI * hFig ) <EOL> wM_Dx = int ( S * PPI * wM ) <EOL> hM_Dx = int ( S * PPI * hM ) <EOL> image = self . render_figure_as_image ( wFig , hFig , PPI ) <EOL> if self . IsPreview ( ) : <EOL> image = image . Scale ( wFig_Dx , hFig_Dx ) <EOL> self . GetDC ( ) . DrawBitmap ( image . ConvertToBitmap ( ) , wM_Dx , hM_Dx , False ) <EOL> return True <EOL> def render_figure_as_image ( self , wFig , hFig , dpi ) : <EOL> """<STR_LIT>""" <EOL> figure = self . figure <EOL> old_dpi = figure . dpi <EOL> figure . dpi = dpi <EOL> old_width = figure . get_figwidth ( ) <EOL> figure . set_figwidth ( wFig ) <EOL> old_height = figure . get_figheight ( ) <EOL> figure . set_figheight ( hFig ) <EOL> old_frameon = figure . frameon <EOL> figure . frameon = False <EOL> wFig_Px = int ( figure . bbox . width ) <EOL> hFig_Px = int ( figure . bbox . height ) <EOL> agg = RendererAgg ( wFig_Px , hFig_Px , dpi ) <EOL> figure . draw ( agg ) <EOL> figure . dpi = old_dpi <EOL> figure . set_figwidth ( old_width ) <EOL> figure . set_figheight ( old_height ) <EOL> figure . frameon = old_frameon <EOL> image = wx . EmptyImage ( wFig_Px , hFig_Px ) <EOL> image . SetData ( agg . tostring_rgb ( ) ) <EOL> return image <EOL> EVT_POINT_ID = wx . NewId ( ) <EOL> def EVT_POINT ( win , id , func ) : <EOL> """<STR_LIT>""" <EOL> win . Connect ( id , - <NUM_LIT:1> , EVT_POINT_ID , func ) <EOL> class PointEvent ( wx . PyCommandEvent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , axes , x , y ) : <EOL> """<STR_LIT>""" <EOL> wx . PyCommandEvent . __init__ ( self , EVT_POINT_ID , id ) <EOL> self . axes = axes <EOL> self . x = x <EOL> self . y = y <EOL> self . xdata , self . ydata = invert_point ( x , y , axes . transData ) <EOL> def Clone ( self ) : <EOL> return PointEvent ( self . GetId ( ) , self . axes , self . x , self . y ) <EOL> EVT_SELECTION_ID = wx . NewId ( ) <EOL> def EVT_SELECTION ( win , id , func ) : <EOL> """<STR_LIT>""" <EOL> win . Connect ( id , - <NUM_LIT:1> , EVT_SELECTION_ID , func ) <EOL> class SelectionEvent ( wx . PyCommandEvent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , axes , x1 , y1 , x2 , y2 ) : <EOL> """<STR_LIT>""" <EOL> wx . PyCommandEvent . __init__ ( self , EVT_SELECTION_ID , id ) <EOL> self . axes = axes <EOL> self . x1 = x1 <EOL> self . y1 = y1 <EOL> self . x2 = x2 <EOL> self . y2 = y2 <EOL> self . x1data , self . y1data = invert_point ( x1 , y1 , axes . transData ) <EOL> self . x2data , self . y2data = invert_point ( x2 , y2 , axes . transData ) <EOL> def Clone ( self ) : <EOL> return SelectionEvent ( self . GetId ( ) , self . axes , self . x1 , self . y1 , <EOL> self . x2 , self . y2 ) <EOL> class PlotPanel ( FigureCanvasWxAgg ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , id , size = ( <NUM_LIT> , <NUM_LIT> ) , dpi = <NUM_LIT> , cursor = True , <EOL> location = True , crosshairs = True , selection = True , zoom = True , <EOL> autoscaleUnzoom = True ) : <EOL> """<STR_LIT>""" <EOL> FigureCanvasWxAgg . __init__ ( self , parent , id , Figure ( size , dpi ) ) <EOL> self . insideOnPaint = False <EOL> self . cursor = CursorChanger ( self , cursor ) <EOL> self . location = LocationPainter ( self , location ) <EOL> self . crosshairs = CrosshairPainter ( self , crosshairs ) <EOL> self . rubberband = RubberbandPainter ( self , selection ) <EOL> rightClickUnzoom = True <EOL> self . director = PlotPanelDirector ( self , zoom , selection , <EOL> rightClickUnzoom , autoscaleUnzoom ) <EOL> self . figure . set_edgecolor ( '<STR_LIT>' ) <EOL> self . figure . set_facecolor ( '<STR_LIT>' ) <EOL> self . SetBackgroundColour ( wx . WHITE ) <EOL> topwin = toplevel_parent_of_window ( self ) <EOL> topwin . Connect ( - <NUM_LIT:1> , self . GetId ( ) , wx . wxEVT_ACTIVATE , self . OnActivate ) <EOL> wx . EVT_ERASE_BACKGROUND ( self , self . OnEraseBackground ) <EOL> wx . EVT_WINDOW_DESTROY ( self , self . OnDestroy ) <EOL> def OnActivate ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self , FigureCanvasWxAgg ) : <EOL> return <EOL> if not evt . GetActive ( ) : <EOL> self . cursor . setNormal ( ) <EOL> self . location . clear ( ) <EOL> self . crosshairs . clear ( ) <EOL> self . rubberband . clear ( ) <EOL> evt . Skip ( ) <EOL> def OnEraseBackground ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def OnDestroy ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> if self . GetId ( ) == evt . GetEventObject ( ) . GetId ( ) : <EOL> topwin = toplevel_parent_of_window ( self ) <EOL> topwin . Disconnect ( - <NUM_LIT:1> , self . GetId ( ) , wx . wxEVT_ACTIVATE ) <EOL> def _onPaint ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self , FigureCanvasWxAgg ) : <EOL> return <EOL> self . insideOnPaint = True <EOL> FigureCanvasWxAgg . _onPaint ( self , evt ) <EOL> self . insideOnPaint = False <EOL> dc = wx . PaintDC ( self ) <EOL> self . location . redraw ( dc ) <EOL> self . crosshairs . redraw ( dc ) <EOL> self . rubberband . redraw ( dc ) <EOL> def get_figure ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . figure <EOL> def set_cursor ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . cursor . setEnabled ( state ) <EOL> def set_location ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . location . setEnabled ( state ) <EOL> def set_crosshairs ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . crosshairs . setEnabled ( state ) <EOL> def set_selection ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . rubberband . setEnabled ( state ) <EOL> self . director . setSelection ( state ) <EOL> def set_zoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . director . setZoomEnabled ( state ) <EOL> def set_autoscale_unzoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . director . setAutoscaleUnzoom ( state ) <EOL> def zoomed ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> return self . director . zoomed ( axes ) <EOL> def draw ( self , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> if ( not self . director . canDraw ( ) <EOL> or not isinstance ( self , FigureCanvasWxAgg ) ) : <EOL> return <EOL> if MATPLOTLIB_0_98_3 : <EOL> FigureCanvasWxAgg . draw ( self , kwds . get ( '<STR_LIT>' , None ) ) <EOL> else : <EOL> FigureCanvasWxAgg . draw ( self , kwds . get ( '<STR_LIT>' , True ) ) <EOL> if not self . insideOnPaint : <EOL> self . location . redraw ( ) <EOL> self . crosshairs . redraw ( ) <EOL> self . rubberband . redraw ( ) <EOL> def notify_point ( self , axes , x , y ) : <EOL> """<STR_LIT>""" <EOL> wx . PostEvent ( self , PointEvent ( self . GetId ( ) , axes , x , y ) ) <EOL> def notify_selection ( self , axes , x1 , y1 , x2 , y2 ) : <EOL> """<STR_LIT>""" <EOL> wx . PostEvent ( self , SelectionEvent ( self . GetId ( ) , axes , x1 , y1 , x2 , y2 ) ) <EOL> def _get_canvas_xy ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> return evt . GetX ( ) , int ( self . figure . bbox . height - evt . GetY ( ) ) <EOL> def _onKeyDown ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . director . keyDown ( evt ) <EOL> def _onKeyUp ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . director . keyUp ( evt ) <EOL> def _onLeftButtonDown ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> x , y = self . _get_canvas_xy ( evt ) <EOL> self . director . leftButtonDown ( evt , x , y ) <EOL> def _onLeftButtonUp ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> x , y = self . _get_canvas_xy ( evt ) <EOL> self . director . leftButtonUp ( evt , x , y ) <EOL> def _onRightButtonDown ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> x , y = self . _get_canvas_xy ( evt ) <EOL> self . director . rightButtonDown ( evt , x , y ) <EOL> def _onRightButtonUp ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> x , y = self . _get_canvas_xy ( evt ) <EOL> self . director . rightButtonUp ( evt , x , y ) <EOL> def _onMotion ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> x , y = self . _get_canvas_xy ( evt ) <EOL> self . director . mouseMotion ( evt , x , y ) <EOL> class PlotFrame ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> ABOUT_TITLE = '<STR_LIT>' <EOL> ABOUT_MESSAGE = ( '<STR_LIT>' % __version__ <EOL> + '<STR_LIT>' <EOL> + '<STR_LIT>' ) <EOL> def __init__ ( self , parent , id , title , size = ( <NUM_LIT> , <NUM_LIT> ) , dpi = <NUM_LIT> , cursor = True , <EOL> location = True , crosshairs = True , selection = True , zoom = True , <EOL> autoscaleUnzoom = True , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> wx . Frame . __init__ ( self , parent , id , title , ** kwds ) <EOL> self . panel = PlotPanel ( self , - <NUM_LIT:1> , size , dpi , cursor , location , <EOL> crosshairs , selection , zoom ) <EOL> pData = wx . PrintData ( ) <EOL> pData . SetPaperId ( wx . PAPER_LETTER ) <EOL> if callable ( getattr ( pData , '<STR_LIT>' , None ) ) : <EOL> pData . SetPrinterCommand ( POSTSCRIPT_PRINTING_COMMAND ) <EOL> self . printer = FigurePrinter ( self , pData ) <EOL> self . create_menus ( ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer . Add ( self . panel , <NUM_LIT:1> , wx . ALL | wx . EXPAND , <NUM_LIT:5> ) <EOL> self . SetSizer ( sizer ) <EOL> self . Fit ( ) <EOL> def create_menus ( self ) : <EOL> mainMenu = wx . MenuBar ( ) <EOL> menu = wx . Menu ( ) <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuFileSave ) <EOL> menu . AppendSeparator ( ) <EOL> if wx . Platform != '<STR_LIT>' : <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuFilePageSetup ) <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuFilePrintPreview ) <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuFilePrint ) <EOL> menu . AppendSeparator ( ) <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuFileClose ) <EOL> mainMenu . Append ( menu , '<STR_LIT>' ) <EOL> menu = wx . Menu ( ) <EOL> id = wx . NewId ( ) <EOL> menu . Append ( id , '<STR_LIT>' , '<STR_LIT>' ) <EOL> wx . EVT_MENU ( self , id , self . OnMenuHelpAbout ) <EOL> mainMenu . Append ( menu , '<STR_LIT>' ) <EOL> self . SetMenuBar ( mainMenu ) <EOL> def OnMenuFileSave ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> fileName = wx . FileSelector ( '<STR_LIT>' , default_extension = '<STR_LIT>' , <EOL> wildcard = ( '<STR_LIT>' <EOL> + '<STR_LIT>' ) , <EOL> parent = self , flags = wx . SAVE | wx . OVERWRITE_PROMPT ) <EOL> if not fileName : <EOL> return <EOL> path , ext = os . path . splitext ( fileName ) <EOL> ext = ext [ <NUM_LIT:1> : ] . lower ( ) <EOL> if ext != '<STR_LIT>' and ext != '<STR_LIT>' : <EOL> error_message = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> wx . MessageBox ( error_message , '<STR_LIT>' , <EOL> parent = self , style = wx . OK | wx . ICON_ERROR ) <EOL> return <EOL> try : <EOL> self . panel . print_figure ( fileName ) <EOL> except IOError , e : <EOL> if e . strerror : <EOL> err = e . strerror <EOL> else : <EOL> err = e <EOL> wx . MessageBox ( '<STR_LIT>' % err , '<STR_LIT>' , <EOL> parent = self , style = wx . OK | wx . ICON_ERROR ) <EOL> def OnMenuFilePageSetup ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . printer . pageSetup ( ) <EOL> def OnMenuFilePrintPreview ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . printer . previewFigure ( self . get_figure ( ) ) <EOL> def OnMenuFilePrint ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . printer . printFigure ( self . get_figure ( ) ) <EOL> def OnMenuFileClose ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> self . Close ( ) <EOL> def OnMenuHelpAbout ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> wx . MessageBox ( self . ABOUT_MESSAGE , self . ABOUT_TITLE , parent = self , <EOL> style = wx . OK ) <EOL> def get_figure ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . panel . figure <EOL> def set_cursor ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_cursor ( state ) <EOL> def set_location ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_location ( state ) <EOL> def set_crosshairs ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_crosshairs ( state ) <EOL> def set_selection ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_selection ( state ) <EOL> def set_zoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_zoom ( state ) <EOL> def set_autoscale_unzoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . panel . set_autoscale_unzoom ( state ) <EOL> def draw ( self ) : <EOL> """<STR_LIT>""" <EOL> self . panel . draw ( ) <EOL> class PlotApp ( wx . App ) : <EOL> """<STR_LIT>""" <EOL> ABOUT_TITLE = None <EOL> ABOUT_MESSAGE = None <EOL> def __init__ ( self , title = "<STR_LIT>" , size = ( <NUM_LIT> , <NUM_LIT> ) , dpi = <NUM_LIT> , cursor = True , <EOL> location = True , crosshairs = True , selection = True , zoom = True , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> self . title = title <EOL> self . size = size <EOL> self . dpi = dpi <EOL> self . cursor = cursor <EOL> self . location = location <EOL> self . crosshairs = crosshairs <EOL> self . selection = selection <EOL> self . zoom = zoom <EOL> wx . App . __init__ ( self , ** kwds ) <EOL> def OnInit ( self ) : <EOL> self . frame = panel = PlotFrame ( None , - <NUM_LIT:1> , self . title , self . size , <EOL> self . dpi , self . cursor , self . location , self . crosshairs , <EOL> self . selection , self . zoom ) <EOL> if self . ABOUT_TITLE is not None : <EOL> panel . ABOUT_TITLE = self . ABOUT_TITLE <EOL> if self . ABOUT_MESSAGE is not None : <EOL> panel . ABOUT_MESSAGE = self . ABOUT_MESSAGE <EOL> panel . Show ( True ) <EOL> return True <EOL> def get_figure ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . frame . get_figure ( ) <EOL> def set_cursor ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . frame . set_cursor ( state ) <EOL> def set_location ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . frame . set_location ( state ) <EOL> def set_crosshairs ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . frame . set_crosshairs ( state ) <EOL> def set_selection ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . frame . set_selection ( state ) <EOL> def set_zoom ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . frame . set_zoom ( state ) <EOL> def draw ( self ) : <EOL> """<STR_LIT>""" <EOL> self . frame . draw ( ) <EOL> class VectorBuffer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . data = np . zeros ( ( <NUM_LIT:16> , ) , np . Float ) <EOL> self . nextRow = <NUM_LIT:0> <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . data [ : ] = <NUM_LIT:0.0> <EOL> self . nextRow = <NUM_LIT:0> <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . data = np . zeros ( ( <NUM_LIT:16> , ) , np . Float ) <EOL> self . nextRow = <NUM_LIT:0> <EOL> def append ( self , point ) : <EOL> """<STR_LIT>""" <EOL> nextRow = self . nextRow <EOL> data = self . data <EOL> resize = False <EOL> if nextRow == data . shape [ <NUM_LIT:0> ] : <EOL> nR = int ( np . ceil ( self . data . shape [ <NUM_LIT:0> ] * <NUM_LIT> ) ) <EOL> resize = True <EOL> if resize : <EOL> self . data = np . zeros ( ( nR , ) , np . Float ) <EOL> self . data [ <NUM_LIT:0> : data . shape [ <NUM_LIT:0> ] ] = data <EOL> self . data [ nextRow ] = point <EOL> self . nextRow += <NUM_LIT:1> <EOL> def getData ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . nextRow == <NUM_LIT:0> : <EOL> return None <EOL> else : <EOL> return self . data [ <NUM_LIT:0> : self . nextRow ] <EOL> class MatrixBuffer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . data = np . zeros ( ( <NUM_LIT:16> , <NUM_LIT:1> ) , np . Float ) <EOL> self . nextRow = <NUM_LIT:0> <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . data [ : , : ] = <NUM_LIT:0.0> <EOL> self . nextRow = <NUM_LIT:0> <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . data = np . zeros ( ( <NUM_LIT:16> , <NUM_LIT:1> ) , np . Float ) <EOL> self . nextRow = <NUM_LIT:0> <EOL> def append ( self , row ) : <EOL> """<STR_LIT>""" <EOL> row = np . asarray ( row , np . Float ) <EOL> nextRow = self . nextRow <EOL> data = self . data <EOL> nPts = row . shape [ <NUM_LIT:0> ] <EOL> if nPts == <NUM_LIT:0> : <EOL> return <EOL> resize = True <EOL> if nextRow == data . shape [ <NUM_LIT:0> ] : <EOL> nC = data . shape [ <NUM_LIT:1> ] <EOL> nR = int ( np . ceil ( self . data . shape [ <NUM_LIT:0> ] * <NUM_LIT> ) ) <EOL> if nC < nPts : <EOL> nC = nPts <EOL> elif data . shape [ <NUM_LIT:1> ] < nPts : <EOL> nR = data . shape [ <NUM_LIT:0> ] <EOL> nC = nPts <EOL> else : <EOL> resize = False <EOL> if resize : <EOL> self . data = np . zeros ( ( nR , nC ) , np . Float ) <EOL> rowEnd , colEnd = data . shape <EOL> self . data [ <NUM_LIT:0> : rowEnd , <NUM_LIT:0> : colEnd ] = data <EOL> self . data [ nextRow , <NUM_LIT:0> : nPts ] = row <EOL> self . nextRow += <NUM_LIT:1> <EOL> def getData ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . nextRow == <NUM_LIT:0> : <EOL> return None <EOL> else : <EOL> return self . data [ <NUM_LIT:0> : self . nextRow , : ] <EOL> def make_delta_bbox ( X1 , Y1 , X2 , Y2 ) : <EOL> """<STR_LIT>""" <EOL> return make_bbox ( get_delta ( X1 , X2 ) , get_delta ( Y1 , Y2 ) ) <EOL> def get_delta ( X1 , X2 ) : <EOL> """<STR_LIT>""" <EOL> n1 = X1 . shape [ <NUM_LIT:0> ] <EOL> n2 = X2 . shape [ <NUM_LIT:0> ] <EOL> if n1 < n2 : <EOL> return X2 [ n1 : ] <EOL> elif n1 == n2 : <EOL> return X2 <EOL> else : <EOL> return X2 <EOL> def make_bbox ( X , Y ) : <EOL> """<STR_LIT>""" <EOL> if X is None or X . shape [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> x1 = x2 = <NUM_LIT:0.0> <EOL> else : <EOL> x1 = min ( X ) <EOL> x2 = max ( X ) <EOL> if Y is None or Y . shape [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> y1 = y2 = <NUM_LIT:0.0> <EOL> else : <EOL> y1 = min ( Y ) <EOL> y2 = max ( Y ) <EOL> return Bbox . from_extents ( x1 , y1 , x2 , y2 ) <EOL> class StripCharter : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , axes ) : <EOL> """<STR_LIT>""" <EOL> self . axes = axes <EOL> self . channels = [ ] <EOL> self . lines = { } <EOL> def setChannels ( self , channels ) : <EOL> """<STR_LIT>""" <EOL> self . lines = None <EOL> self . channels = channels [ : ] <EOL> self . axes . legend_ = None <EOL> self . axes . lines = [ ] <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> axes = self . axes <EOL> figureCanvas = axes . figure . canvas <EOL> zoomed = figureCanvas . zoomed ( axes ) <EOL> redraw = False <EOL> if self . lines is None : <EOL> self . _create_plot ( ) <EOL> redraw = True <EOL> else : <EOL> for channel in self . channels : <EOL> redraw = self . _update_channel ( channel , zoomed ) or redraw <EOL> if redraw : <EOL> if not zoomed : <EOL> axes . autoscale_view ( ) <EOL> figureCanvas . draw ( ) <EOL> def _create_plot ( self ) : <EOL> """<STR_LIT>""" <EOL> self . lines = { } <EOL> axes = self . axes <EOL> styleGen = _process_plot_var_args ( axes ) <EOL> for channel in self . channels : <EOL> self . _plot_channel ( channel , styleGen ) <EOL> if self . channels : <EOL> lines = [ self . lines [ x ] for x in self . channels ] <EOL> labels = [ x . get_label ( ) for x in lines ] <EOL> self . axes . legend ( lines , labels , numpoints = <NUM_LIT:2> , <EOL> prop = FontProperties ( size = '<STR_LIT>' ) ) <EOL> def _plot_channel ( self , channel , styleGen ) : <EOL> """<STR_LIT>""" <EOL> empty = False <EOL> x = channel . getX ( ) <EOL> y = channel . getY ( ) <EOL> if x is None or y is None : <EOL> x = y = [ ] <EOL> empty = True <EOL> line = styleGen ( x , y ) . next ( ) <EOL> line . _wxmpl_empty_line = empty <EOL> if channel . getColor ( ) is not None : <EOL> line . set_color ( channel . getColor ( ) ) <EOL> if channel . getStyle ( ) is not None : <EOL> line . set_linestyle ( channel . getStyle ( ) ) <EOL> if channel . getMarker ( ) is not None : <EOL> line . set_marker ( channel . getMarker ( ) ) <EOL> line . set_markeredgecolor ( line . get_color ( ) ) <EOL> line . set_markerfacecolor ( line . get_color ( ) ) <EOL> line . set_label ( channel . getLabel ( ) ) <EOL> self . lines [ channel ] = line <EOL> if not empty : <EOL> self . axes . add_line ( line ) <EOL> def _update_channel ( self , channel , zoomed ) : <EOL> """<STR_LIT>""" <EOL> if channel . hasChanged ( ) : <EOL> channel . setChanged ( False ) <EOL> else : <EOL> return False <EOL> axes = self . axes <EOL> line = self . lines [ channel ] <EOL> newX = channel . getX ( ) <EOL> newY = channel . getY ( ) <EOL> if newX is None or newY is None : <EOL> return False <EOL> oldX = line . _x <EOL> oldY = line . _y <EOL> x , y = newX , newY <EOL> line . set_data ( x , y ) <EOL> if line . _wxmpl_empty_line : <EOL> axes . add_line ( line ) <EOL> line . _wxmpl_empty_line = False <EOL> else : <EOL> if line . get_transform ( ) != axes . transData : <EOL> xys = axes . _get_verts_in_data_coords ( <EOL> line . get_transform ( ) , zip ( x , y ) ) <EOL> else : <EOL> xys = np . zeros ( ( x . shape [ <NUM_LIT:0> ] , <NUM_LIT:2> ) , np . Float ) <EOL> xys [ : , <NUM_LIT:0> ] = x <EOL> xys [ : , <NUM_LIT:1> ] = y <EOL> axes . update_datalim ( xys ) <EOL> if zoomed : <EOL> return axes . viewLim . overlaps ( <EOL> make_delta_bbox ( oldX , oldY , newX , newY ) ) <EOL> else : <EOL> return True <EOL> class Channel : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , color = None , style = None , marker = None ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . color = color <EOL> self . style = style <EOL> self . marker = marker <EOL> self . changed = False <EOL> def getLabel ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . name <EOL> def getColor ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . color <EOL> def getStyle ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . style <EOL> def getMarker ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . marker <EOL> def hasChanged ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . changed <EOL> def setChanged ( self , changed ) : <EOL> """<STR_LIT>""" <EOL> self . changed = changed <EOL> def getX ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def getY ( self ) : <EOL> """<STR_LIT>""" <EOL> return None </s>
