<s> """<STR_LIT>""" <EOL> import itertools <EOL> import io <EOL> import base64 <EOL> import numpy as np <EOL> import warnings <EOL> import matplotlib <EOL> from matplotlib . colors import colorConverter <EOL> from matplotlib . path import Path <EOL> from matplotlib . markers import MarkerStyle <EOL> from matplotlib . transforms import Affine2D <EOL> from matplotlib import ticker <EOL> def color_to_hex ( color ) : <EOL> """<STR_LIT>""" <EOL> if color is None or colorConverter . to_rgba ( color ) [ <NUM_LIT:3> ] == <NUM_LIT:0> : <EOL> return '<STR_LIT:none>' <EOL> else : <EOL> rgb = colorConverter . to_rgb ( color ) <EOL> return '<STR_LIT>' . format ( * ( int ( <NUM_LIT:255> * c ) for c in rgb ) ) <EOL> def _many_to_one ( input_dict ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ( key , val ) <EOL> for keys , val in input_dict . items ( ) <EOL> for key in keys ) <EOL> LINESTYLES = _many_to_one ( { ( '<STR_LIT>' , '<STR_LIT:->' , ( None , None ) ) : '<STR_LIT:none>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT::>' ) : "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT:U+0020>' , '<STR_LIT:None>' , '<STR_LIT:none>' ) : None } ) <EOL> def get_dasharray ( obj ) : <EOL> """<STR_LIT>""" <EOL> if obj . __dict__ . get ( '<STR_LIT>' , None ) is not None : <EOL> return '<STR_LIT:U+002C>' . join ( map ( str , obj . _dashSeq ) ) <EOL> else : <EOL> ls = obj . get_linestyle ( ) <EOL> dasharray = LINESTYLES . get ( ls , '<STR_LIT>' ) <EOL> if dasharray == '<STR_LIT>' : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( ls ) ) <EOL> dasharray = LINESTYLES [ '<STR_LIT>' ] <EOL> return dasharray <EOL> PATH_DICT = { Path . LINETO : '<STR_LIT:L>' , <EOL> Path . MOVETO : '<STR_LIT:M>' , <EOL> Path . CURVE3 : '<STR_LIT:S>' , <EOL> Path . CURVE4 : '<STR_LIT:C>' , <EOL> Path . CLOSEPOLY : '<STR_LIT>' } <EOL> def SVG_path ( path , transform = None , simplify = False ) : <EOL> """<STR_LIT>""" <EOL> if transform is not None : <EOL> path = path . transformed ( transform ) <EOL> vc_tuples = [ ( vertices if path_code != Path . CLOSEPOLY else [ ] , <EOL> PATH_DICT [ path_code ] ) <EOL> for ( vertices , path_code ) <EOL> in path . iter_segments ( simplify = simplify ) ] <EOL> if not vc_tuples : <EOL> return np . zeros ( ( <NUM_LIT:0> , <NUM_LIT:2> ) ) , [ ] <EOL> else : <EOL> vertices , codes = zip ( * vc_tuples ) <EOL> vertices = np . array ( list ( itertools . chain ( * vertices ) ) ) . reshape ( - <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> return vertices , list ( codes ) <EOL> def get_path_style ( path , fill = True ) : <EOL> """<STR_LIT>""" <EOL> style = { } <EOL> style [ '<STR_LIT>' ] = path . get_alpha ( ) <EOL> if style [ '<STR_LIT>' ] is None : <EOL> style [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> style [ '<STR_LIT>' ] = color_to_hex ( path . get_edgecolor ( ) ) <EOL> if fill : <EOL> style [ '<STR_LIT>' ] = color_to_hex ( path . get_facecolor ( ) ) <EOL> else : <EOL> style [ '<STR_LIT>' ] = '<STR_LIT:none>' <EOL> style [ '<STR_LIT>' ] = path . get_linewidth ( ) <EOL> style [ '<STR_LIT>' ] = get_dasharray ( path ) <EOL> style [ '<STR_LIT>' ] = path . get_zorder ( ) <EOL> return style <EOL> def get_line_style ( line ) : <EOL> """<STR_LIT>""" <EOL> style = { } <EOL> style [ '<STR_LIT>' ] = line . get_alpha ( ) <EOL> if style [ '<STR_LIT>' ] is None : <EOL> style [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> style [ '<STR_LIT>' ] = color_to_hex ( line . get_color ( ) ) <EOL> style [ '<STR_LIT>' ] = line . get_linewidth ( ) <EOL> style [ '<STR_LIT>' ] = get_dasharray ( line ) <EOL> style [ '<STR_LIT>' ] = line . get_zorder ( ) <EOL> return style <EOL> def get_marker_style ( line ) : <EOL> """<STR_LIT>""" <EOL> style = { } <EOL> style [ '<STR_LIT>' ] = line . get_alpha ( ) <EOL> if style [ '<STR_LIT>' ] is None : <EOL> style [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> style [ '<STR_LIT>' ] = color_to_hex ( line . get_markerfacecolor ( ) ) <EOL> style [ '<STR_LIT>' ] = color_to_hex ( line . get_markeredgecolor ( ) ) <EOL> style [ '<STR_LIT>' ] = line . get_markeredgewidth ( ) <EOL> style [ '<STR_LIT>' ] = line . get_marker ( ) <EOL> markerstyle = MarkerStyle ( line . get_marker ( ) ) <EOL> markersize = line . get_markersize ( ) <EOL> markertransform = ( markerstyle . get_transform ( ) + <EOL> Affine2D ( ) . scale ( markersize , - markersize ) ) <EOL> style [ '<STR_LIT>' ] = SVG_path ( markerstyle . get_path ( ) , <EOL> markertransform ) <EOL> style [ '<STR_LIT>' ] = markersize <EOL> style [ '<STR_LIT>' ] = line . get_zorder ( ) <EOL> return style <EOL> def get_text_style ( text ) : <EOL> """<STR_LIT>""" <EOL> style = { } <EOL> style [ '<STR_LIT>' ] = text . get_alpha ( ) <EOL> if style [ '<STR_LIT>' ] is None : <EOL> style [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> style [ '<STR_LIT>' ] = text . get_size ( ) <EOL> style [ '<STR_LIT>' ] = color_to_hex ( text . get_color ( ) ) <EOL> style [ '<STR_LIT>' ] = text . get_horizontalalignment ( ) <EOL> style [ '<STR_LIT>' ] = text . get_verticalalignment ( ) <EOL> style [ '<STR_LIT>' ] = text . _multialignment <EOL> style [ '<STR_LIT>' ] = text . get_rotation ( ) <EOL> style [ '<STR_LIT>' ] = text . get_zorder ( ) <EOL> return style <EOL> def get_axis_properties ( axis ) : <EOL> """<STR_LIT>""" <EOL> props = { } <EOL> label1On = axis . _major_tick_kw . get ( '<STR_LIT>' , True ) <EOL> if isinstance ( axis , matplotlib . axis . XAxis ) : <EOL> if label1On : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> else : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> elif isinstance ( axis , matplotlib . axis . YAxis ) : <EOL> if label1On : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT:left>" <EOL> else : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT:right>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" . format ( axis ) ) <EOL> locator = axis . get_major_locator ( ) <EOL> props [ '<STR_LIT>' ] = len ( locator ( ) ) <EOL> if isinstance ( locator , ticker . FixedLocator ) : <EOL> props [ '<STR_LIT>' ] = list ( locator ( ) ) <EOL> else : <EOL> props [ '<STR_LIT>' ] = None <EOL> formatter = axis . get_major_formatter ( ) <EOL> if isinstance ( formatter , ticker . NullFormatter ) : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> elif isinstance ( formatter , ticker . FixedFormatter ) : <EOL> props [ '<STR_LIT>' ] = list ( formatter . seq ) <EOL> elif not any ( label . get_visible ( ) for label in axis . get_ticklabels ( ) ) : <EOL> props [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> else : <EOL> props [ '<STR_LIT>' ] = None <EOL> props [ '<STR_LIT>' ] = axis . get_scale ( ) <EOL> labels = axis . get_ticklabels ( ) <EOL> if labels : <EOL> props [ '<STR_LIT>' ] = labels [ <NUM_LIT:0> ] . get_fontsize ( ) <EOL> else : <EOL> props [ '<STR_LIT>' ] = None <EOL> props [ '<STR_LIT>' ] = get_grid_style ( axis ) <EOL> return props <EOL> def get_grid_style ( axis ) : <EOL> gridlines = axis . get_gridlines ( ) <EOL> if axis . _gridOnMajor and len ( gridlines ) > <NUM_LIT:0> : <EOL> color = color_to_hex ( gridlines [ <NUM_LIT:0> ] . get_color ( ) ) <EOL> alpha = gridlines [ <NUM_LIT:0> ] . get_alpha ( ) <EOL> dasharray = get_dasharray ( gridlines [ <NUM_LIT:0> ] ) <EOL> return dict ( gridOn = True , <EOL> color = color , <EOL> dasharray = dasharray , <EOL> alpha = alpha ) <EOL> else : <EOL> return { "<STR_LIT>" : False } <EOL> def get_figure_properties ( fig ) : <EOL> return { '<STR_LIT>' : fig . get_figwidth ( ) , <EOL> '<STR_LIT>' : fig . get_figheight ( ) , <EOL> '<STR_LIT>' : fig . dpi } <EOL> def get_axes_properties ( ax ) : <EOL> props = { '<STR_LIT>' : color_to_hex ( ax . patch . get_facecolor ( ) ) , <EOL> '<STR_LIT>' : ax . patch . get_alpha ( ) , <EOL> '<STR_LIT>' : ax . get_position ( ) . bounds , <EOL> '<STR_LIT>' : ax . get_navigate ( ) , <EOL> '<STR_LIT>' : ax . axison , <EOL> '<STR_LIT>' : ax . get_frame_on ( ) , <EOL> '<STR_LIT>' : [ get_axis_properties ( ax . xaxis ) , <EOL> get_axis_properties ( ax . yaxis ) ] } <EOL> for axname in [ '<STR_LIT:x>' , '<STR_LIT:y>' ] : <EOL> axis = getattr ( ax , axname + '<STR_LIT>' ) <EOL> domain = getattr ( ax , '<STR_LIT>' . format ( axname ) ) ( ) <EOL> lim = domain <EOL> if isinstance ( axis . converter , matplotlib . dates . DateConverter ) : <EOL> scale = '<STR_LIT:date>' <EOL> try : <EOL> import pandas as pd <EOL> from pandas . tseries . converter import PeriodConverter <EOL> except ImportError : <EOL> pd = None <EOL> if ( pd is not None and isinstance ( axis . converter , <EOL> PeriodConverter ) ) : <EOL> _dates = [ pd . Period ( ordinal = int ( d ) , freq = axis . freq ) <EOL> for d in domain ] <EOL> domain = [ ( d . year , d . month - <NUM_LIT:1> , d . day , <EOL> d . hour , d . minute , d . second , <NUM_LIT:0> ) <EOL> for d in _dates ] <EOL> else : <EOL> domain = [ ( d . year , d . month - <NUM_LIT:1> , d . day , <EOL> d . hour , d . minute , d . second , <EOL> d . microsecond * <NUM_LIT> ) <EOL> for d in matplotlib . dates . num2date ( domain ) ] <EOL> else : <EOL> scale = axis . get_scale ( ) <EOL> if scale not in [ '<STR_LIT:date>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( axis [ axname ] . get_scale ( ) ) ) <EOL> props [ axname + '<STR_LIT>' ] = scale <EOL> props [ axname + '<STR_LIT>' ] = lim <EOL> props [ axname + '<STR_LIT>' ] = domain <EOL> return props <EOL> def iter_all_children ( obj , skipContainers = False ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( obj , '<STR_LIT>' ) and len ( obj . get_children ( ) ) > <NUM_LIT:0> : <EOL> for child in obj . get_children ( ) : <EOL> if not skipContainers : <EOL> yield child <EOL> for grandchild in iter_all_children ( child , skipContainers ) : <EOL> yield grandchild <EOL> else : <EOL> yield obj <EOL> def get_legend_properties ( ax , legend ) : <EOL> handles , labels = ax . get_legend_handles_labels ( ) <EOL> visible = legend . get_visible ( ) <EOL> return { '<STR_LIT>' : handles , '<STR_LIT>' : labels , '<STR_LIT>' : visible } <EOL> def image_to_base64 ( image ) : <EOL> """<STR_LIT>""" <EOL> ax = image . axes <EOL> binary_buffer = io . BytesIO ( ) <EOL> lim = ax . axis ( ) <EOL> ax . axis ( image . get_extent ( ) ) <EOL> image . write_png ( binary_buffer ) <EOL> ax . axis ( lim ) <EOL> binary_buffer . seek ( <NUM_LIT:0> ) <EOL> return base64 . b64encode ( binary_buffer . read ( ) ) . decode ( '<STR_LIT:utf-8>' ) </s>
