<s> from tempfile import TemporaryFile <EOL> import matplotlib as mpl <EOL> import matplotlib . pyplot as plt <EOL> from mpl_toolkits . basemap import Basemap <EOL> from mpl_toolkits . axes_grid1 import ImageGrid <EOL> import scipy . stats . mstats as mstats <EOL> import numpy as np <EOL> import numpy . ma as ma <EOL> mpl . rc ( '<STR_LIT:image>' , cmap = '<STR_LIT>' ) <EOL> def set_cmap ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmap = plt . get_cmap ( name ) <EOL> mpl . rc ( '<STR_LIT:image>' , cmap = cmap . name ) <EOL> def _nice_intervals ( data , nlevs ) : <EOL> '''<STR_LIT>''' <EOL> data = data . ravel ( ) <EOL> mn = mstats . scoreatpercentile ( data , <NUM_LIT:5> ) <EOL> mx = mstats . scoreatpercentile ( data , <NUM_LIT> ) <EOL> if mn < <NUM_LIT:0> and mx > <NUM_LIT:0> : <EOL> level = max ( abs ( mn ) , abs ( mx ) ) <EOL> mnlvl = - <NUM_LIT:1> * level <EOL> mxlvl = level <EOL> else : <EOL> mnlvl = mn <EOL> mxlvl = mx <EOL> locator = mpl . ticker . MaxNLocator ( nlevs ) <EOL> clevs = locator . tick_values ( mnlvl , mxlvl ) <EOL> clevs = clevs [ ( clevs >= mnlvl ) & ( clevs <= mxlvl ) ] <EOL> return clevs <EOL> def _best_grid_shape ( nplots , oldshape ) : <EOL> '''<STR_LIT>''' <EOL> nrows , ncols = oldshape <EOL> size = nrows * ncols <EOL> diff = size - nplots <EOL> if diff < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' % ( nrows , ncols ) ) <EOL> else : <EOL> while diff >= ncols : <EOL> nrows -= <NUM_LIT:1> <EOL> size = nrows * ncols <EOL> diff = size - nplots <EOL> if nrows == <NUM_LIT:1> : <EOL> ncols = nplots <EOL> newshape = nrows , ncols <EOL> return newshape <EOL> def _fig_size ( gridshape , aspect = None ) : <EOL> '''<STR_LIT>''' <EOL> if aspect is None : <EOL> aspect = <NUM_LIT> / <NUM_LIT> <EOL> nrows , ncols = gridshape <EOL> if nrows >= ncols : <EOL> width , height = ( aspect * <NUM_LIT> ) , <NUM_LIT> * ( nrows / ncols ) <EOL> else : <EOL> width , height = ( aspect * <NUM_LIT> ) * ( ncols / nrows ) , <NUM_LIT> <EOL> return width , height <EOL> def draw_taylor_diagram ( results , names , refname , fname , fmt = '<STR_LIT>' , <EOL> gridshape = ( <NUM_LIT:1> , <NUM_LIT:1> ) , ptitle = '<STR_LIT>' , subtitles = None , <EOL> pos = '<STR_LIT>' , frameon = True , radmax = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> if results . ndim == <NUM_LIT:2> : <EOL> results = results . reshape ( <NUM_LIT:1> , * results . shape ) <EOL> nplots = results . shape [ <NUM_LIT:0> ] <EOL> gridshape = _best_grid_shape ( nplots , gridshape ) <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( <NUM_LIT> , <NUM_LIT:11> ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> for i , data in enumerate ( results ) : <EOL> rect = gridshape + ( i + <NUM_LIT:1> , ) <EOL> rect = str ( rect [ <NUM_LIT:0> ] ) + str ( rect [ <NUM_LIT:1> ] ) + str ( rect [ <NUM_LIT:2> ] ) <EOL> dia = TaylorDiagram ( <NUM_LIT:1> , fig = fig , rect = rect , label = refname , radmax = radmax ) <EOL> for i , ( stddev , corrcoef ) in enumerate ( data ) : <EOL> dia . add_sample ( stddev , corrcoef , marker = '<STR_LIT>' % ( i + <NUM_LIT:1> ) , ms = <NUM_LIT:6> , <EOL> label = names [ i ] ) <EOL> if subtitles is not None : <EOL> dia . _ax . set_title ( subtitles [ i ] ) <EOL> legend = fig . legend ( dia . samplePoints , <EOL> [ p . get_label ( ) for p in dia . samplePoints ] , <EOL> handlelength = <NUM_LIT:0.> , prop = { '<STR_LIT:size>' : <NUM_LIT:10> } , numpoints = <NUM_LIT:1> , <EOL> loc = pos ) <EOL> legend . draw_frame ( frameon ) <EOL> plt . subplots_adjust ( wspace = <NUM_LIT:0> ) <EOL> fig . suptitle ( ptitle ) <EOL> plt . tight_layout ( <NUM_LIT> , <NUM_LIT> ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_subregions ( subregions , lats , lons , fname , fmt = '<STR_LIT>' , ptitle = '<STR_LIT>' , <EOL> parallels = None , meridians = None , subregion_masks = None ) : <EOL> '''<STR_LIT>''' <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> lonmin = lons . min ( ) <EOL> lonmax = lons . max ( ) <EOL> latmin = lats . min ( ) <EOL> latmax = lats . max ( ) <EOL> m = Basemap ( projection = '<STR_LIT>' , llcrnrlat = latmin , urcrnrlat = latmax , <EOL> llcrnrlon = lonmin , urcrnrlon = lonmax , resolution = '<STR_LIT:l>' , ax = ax ) <EOL> m . drawcoastlines ( linewidth = <NUM_LIT:1> ) <EOL> m . drawcountries ( linewidth = <NUM_LIT> ) <EOL> m . drawstates ( ) <EOL> length = max ( ( latmax - latmin ) , ( lonmax - lonmin ) ) / <NUM_LIT:5> <EOL> if length <= <NUM_LIT:1> : <EOL> dlatlon = <NUM_LIT:1> <EOL> elif length <= <NUM_LIT:5> : <EOL> dlatlon = <NUM_LIT:5> <EOL> else : <EOL> dlatlon = np . round ( length , decimals = - <NUM_LIT:1> ) <EOL> if meridians is None : <EOL> meridians = np . r_ [ np . arange ( <NUM_LIT:0> , - <NUM_LIT> , - dlatlon ) [ : : - <NUM_LIT:1> ] , np . arange ( <NUM_LIT:0> , <NUM_LIT> , dlatlon ) ] <EOL> if parallels is None : <EOL> parallels = np . r_ [ np . arange ( <NUM_LIT:0> , - <NUM_LIT> , - dlatlon ) [ : : - <NUM_LIT:1> ] , np . arange ( <NUM_LIT:0> , <NUM_LIT> , dlatlon ) ] <EOL> m . drawmeridians ( meridians , labels = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , linewidth = <NUM_LIT> , fontsize = <NUM_LIT:10> ) <EOL> m . drawparallels ( parallels , labels = [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , linewidth = <NUM_LIT> , fontsize = <NUM_LIT:10> ) <EOL> cmap = plt . cm . rainbow <EOL> norm = mpl . colors . BoundaryNorm ( np . arange ( <NUM_LIT:1> , len ( subregions ) + <NUM_LIT:3> ) , cmap . N ) <EOL> for i , reg in enumerate ( subregions ) : <EOL> if subregion_masks is not None and reg . name in subregion_masks . keys ( ) : <EOL> domain = ( i + <NUM_LIT:1> ) * subregion_masks [ reg . name ] <EOL> else : <EOL> domain = ( i + <NUM_LIT:1> ) * np . ones ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> nlats , nlons = domain . shape <EOL> domain = ma . masked_equal ( domain , <NUM_LIT:0> ) <EOL> reglats = np . linspace ( reg . lat_min , reg . lat_max , nlats ) <EOL> reglons = np . linspace ( reg . lon_min , reg . lon_max , nlons ) <EOL> reglons , reglats = np . meshgrid ( reglons , reglats ) <EOL> x , y = m ( reglons , reglats ) <EOL> m . pcolormesh ( x , y , domain , cmap = cmap , norm = norm , alpha = <NUM_LIT> ) <EOL> xm , ym = x . mean ( ) , y . mean ( ) <EOL> m . plot ( xm , ym , marker = '<STR_LIT>' % ( "<STR_LIT:R>" + str ( i + <NUM_LIT:1> ) ) , markersize = <NUM_LIT:12> , color = '<STR_LIT:k>' ) <EOL> ax . set_title ( ptitle ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_time_series ( results , times , labels , fname , fmt = '<STR_LIT>' , gridshape = ( <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> xlabel = '<STR_LIT>' , ylabel = '<STR_LIT>' , ptitle = '<STR_LIT>' , subtitles = None , <EOL> label_month = False , yscale = '<STR_LIT>' , aspect = None ) : <EOL> '''<STR_LIT>''' <EOL> if results . ndim == <NUM_LIT:2> : <EOL> results = results . reshape ( <NUM_LIT:1> , * results . shape ) <EOL> nplots = results . shape [ <NUM_LIT:0> ] <EOL> gridshape = _best_grid_shape ( nplots , gridshape ) <EOL> width , height = _fig_size ( gridshape ) <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( width , height ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> grid = ImageGrid ( fig , <NUM_LIT> , <EOL> nrows_ncols = gridshape , <EOL> axes_pad = <NUM_LIT> , <EOL> share_all = True , <EOL> add_all = True , <EOL> ngrids = nplots , <EOL> label_mode = '<STR_LIT:L>' , <EOL> aspect = False , <EOL> cbar_mode = '<STR_LIT>' , <EOL> cbar_location = '<STR_LIT>' , <EOL> cbar_size = <NUM_LIT> , <EOL> cbar_pad = <NUM_LIT> <EOL> ) <EOL> for i , ax in enumerate ( grid ) : <EOL> data = results [ i ] <EOL> if label_month : <EOL> xfmt = mpl . dates . DateFormatter ( '<STR_LIT>' ) <EOL> xloc = mpl . dates . MonthLocator ( ) <EOL> ax . xaxis . set_major_formatter ( xfmt ) <EOL> ax . xaxis . set_major_locator ( xloc ) <EOL> ax . set_yscale ( yscale ) <EOL> lines = [ ] <EOL> ymin , ymax = <NUM_LIT:0> , <NUM_LIT:0> <EOL> for tSeries in data : <EOL> line = ax . plot_date ( times , tSeries , '<STR_LIT>' ) <EOL> lines . extend ( line ) <EOL> cmin , cmax = tSeries . min ( ) , tSeries . max ( ) <EOL> ymin = min ( ymin , cmin ) <EOL> ymax = max ( ymax , cmax ) <EOL> ymin = ymin - ( ( ymax - ymin ) * <NUM_LIT:0.1> ) <EOL> ymax = ymax + ( ( ymax - ymin ) * <NUM_LIT:0.1> ) <EOL> ax . set_ylim ( ( ymin , ymax ) ) <EOL> if subtitles is not None : <EOL> ax . set_title ( subtitles [ i ] , fontsize = '<STR_LIT>' ) <EOL> fax = fig . add_subplot ( <NUM_LIT> , frameon = False ) <EOL> fax . tick_params ( labelcolor = '<STR_LIT:none>' , top = '<STR_LIT>' , bottom = '<STR_LIT>' , left = '<STR_LIT>' , right = '<STR_LIT>' ) <EOL> fax . set_ylabel ( ylabel ) <EOL> fax . set_title ( ptitle , fontsize = <NUM_LIT:16> ) <EOL> fax . title . set_y ( <NUM_LIT> ) <EOL> cax = ax . cax <EOL> cax . set_frame_on ( False ) <EOL> cax . set_xticks ( [ ] ) <EOL> cax . set_yticks ( [ ] ) <EOL> cax . legend ( ( lines ) , labels , loc = '<STR_LIT>' , ncol = <NUM_LIT:10> , fontsize = '<STR_LIT>' , <EOL> mode = '<STR_LIT>' , frameon = False ) <EOL> cax . set_title ( xlabel , fontsize = <NUM_LIT:12> ) <EOL> cax . title . set_y ( - <NUM_LIT> ) <EOL> for ax in grid : <EOL> for xtick in ax . get_xticklabels ( ) : <EOL> xtick . set_ha ( '<STR_LIT:right>' ) <EOL> xtick . set_rotation ( <NUM_LIT:30> ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_barchart ( results , yvalues , fname , ptitle = '<STR_LIT>' , fmt = '<STR_LIT>' , <EOL> xlabel = '<STR_LIT>' , ylabel = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> y_pos = list ( range ( len ( yvalues ) ) ) <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> ax = plt . subplot ( <NUM_LIT> ) <EOL> plt . barh ( y_pos , results , align = "<STR_LIT>" , height = <NUM_LIT> , linewidth = <NUM_LIT:0> ) <EOL> plt . yticks ( y_pos , yvalues ) <EOL> plt . tick_params ( axis = "<STR_LIT>" , which = "<STR_LIT>" , bottom = "<STR_LIT>" , top = "<STR_LIT>" , labelbottom = "<STR_LIT>" , left = "<STR_LIT>" , right = "<STR_LIT>" , labelleft = "<STR_LIT>" ) <EOL> ax . spines [ "<STR_LIT>" ] . set_visible ( False ) <EOL> ax . spines [ "<STR_LIT:right>" ] . set_visible ( False ) <EOL> ymin = min ( y_pos ) <EOL> ymax = max ( y_pos ) <EOL> ymin = min ( ( ymin - ( ( ymax - ymin ) * <NUM_LIT:0.1> ) / <NUM_LIT:2> ) , <NUM_LIT:0.5> ) <EOL> ymax = ymax + ( ( ymax - ymin ) * <NUM_LIT:0.1> ) <EOL> ax . set_ylim ( ( ymin , ymax ) ) <EOL> plt . xlabel ( xlabel ) <EOL> plt . tight_layout ( ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_marker_on_map ( lat , lon , fname , fmt = '<STR_LIT>' , location_name = '<STR_LIT:U+0020>' , gridshape = ( <NUM_LIT:1> , <NUM_LIT:1> ) ) : <EOL> '''<STR_LIT>''' <EOL> fig = plt . figure ( ) <EOL> fig . dpi = <NUM_LIT> <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> m = Basemap ( projection = '<STR_LIT>' , resolution = '<STR_LIT:c>' , llcrnrlat = lat - <NUM_LIT:30> , urcrnrlat = lat + <NUM_LIT:30> , llcrnrlon = lon - <NUM_LIT> , urcrnrlon = lon + <NUM_LIT> ) <EOL> m . drawcoastlines ( linewidth = <NUM_LIT:1> ) <EOL> m . drawcountries ( linewidth = <NUM_LIT:1> ) <EOL> m . drawmapboundary ( fill_color = '<STR_LIT>' ) <EOL> m . fillcontinents ( color = '<STR_LIT>' , lake_color = '<STR_LIT>' ) <EOL> m . ax = ax <EOL> xpt , ypt = m ( lon , lat ) <EOL> m . plot ( xpt , ypt , '<STR_LIT>' ) <EOL> plt . text ( xpt + <NUM_LIT:0.5> , ypt + <NUM_LIT> , location_name + '<STR_LIT>' % ( lon , lat ) ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_contour_map ( dataset , lats , lons , fname , fmt = '<STR_LIT>' , gridshape = ( <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> clabel = '<STR_LIT>' , ptitle = '<STR_LIT>' , subtitles = None , cmap = None , <EOL> clevs = None , nlevs = <NUM_LIT:10> , parallels = None , meridians = None , <EOL> extend = '<STR_LIT>' , aspect = <NUM_LIT> / <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> if dataset . ndim == <NUM_LIT:2> or ( dataset . ndim == <NUM_LIT:3> and dataset . shape [ <NUM_LIT:0> ] == <NUM_LIT:1> ) : <EOL> if dataset . ndim == <NUM_LIT:2> : <EOL> dataset = dataset . reshape ( <NUM_LIT:1> , * dataset . shape ) <EOL> mlabels = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> plabels = [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> else : <EOL> mlabels = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> plabels = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> nplots = dataset . shape [ <NUM_LIT:0> ] <EOL> gridshape = _best_grid_shape ( nplots , gridshape ) <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> grid = ImageGrid ( fig , <NUM_LIT> , <EOL> nrows_ncols = gridshape , <EOL> axes_pad = <NUM_LIT> , <EOL> share_all = True , <EOL> add_all = True , <EOL> ngrids = nplots , <EOL> label_mode = '<STR_LIT:L>' , <EOL> cbar_mode = '<STR_LIT>' , <EOL> cbar_location = '<STR_LIT>' , <EOL> cbar_size = <NUM_LIT> , <EOL> cbar_pad = '<STR_LIT>' <EOL> ) <EOL> lonmin = lons . min ( ) <EOL> lonmax = lons . max ( ) <EOL> latmin = lats . min ( ) <EOL> latmax = lats . max ( ) <EOL> m = Basemap ( projection = '<STR_LIT>' , llcrnrlat = latmin , urcrnrlat = latmax , <EOL> llcrnrlon = lonmin , urcrnrlon = lonmax , resolution = '<STR_LIT:l>' ) <EOL> if lats . ndim == <NUM_LIT:1> and lons . ndim == <NUM_LIT:1> : <EOL> lons , lats = np . meshgrid ( lons , lats ) <EOL> if clevs is None : <EOL> clevs = _nice_intervals ( dataset , nlevs ) <EOL> extend = '<STR_LIT>' <EOL> cmap = plt . get_cmap ( cmap ) <EOL> length = max ( ( latmax - latmin ) , ( lonmax - lonmin ) ) / <NUM_LIT:5> <EOL> if length <= <NUM_LIT:1> : <EOL> dlatlon = <NUM_LIT:1> <EOL> elif length <= <NUM_LIT:5> : <EOL> dlatlon = <NUM_LIT:5> <EOL> else : <EOL> dlatlon = np . round ( length , decimals = - <NUM_LIT:1> ) <EOL> if meridians is None : <EOL> meridians = np . r_ [ np . arange ( <NUM_LIT:0> , - <NUM_LIT> , - dlatlon ) [ : : - <NUM_LIT:1> ] , np . arange ( <NUM_LIT:0> , <NUM_LIT> , dlatlon ) ] <EOL> if parallels is None : <EOL> parallels = np . r_ [ np . arange ( <NUM_LIT:0> , - <NUM_LIT> , - dlatlon ) [ : : - <NUM_LIT:1> ] , np . arange ( <NUM_LIT:0> , <NUM_LIT> , dlatlon ) ] <EOL> x , y = m ( lons , lats ) <EOL> for i , ax in enumerate ( grid ) : <EOL> data = dataset [ i ] <EOL> m . ax = ax <EOL> m . drawcoastlines ( linewidth = <NUM_LIT:1> ) <EOL> m . drawcountries ( linewidth = <NUM_LIT> ) <EOL> m . drawmeridians ( meridians , labels = mlabels , linewidth = <NUM_LIT> , fontsize = <NUM_LIT:10> ) <EOL> m . drawparallels ( parallels , labels = plabels , linewidth = <NUM_LIT> , fontsize = <NUM_LIT:10> ) <EOL> cs = m . contourf ( x , y , data , cmap = cmap , levels = clevs , extend = extend ) <EOL> if subtitles is not None : <EOL> ax . set_title ( subtitles [ i ] , fontsize = '<STR_LIT>' ) <EOL> cbar = fig . colorbar ( cs , cax = ax . cax , drawedges = True , orientation = '<STR_LIT>' , extendfrac = '<STR_LIT>' ) <EOL> cbar . set_label ( clabel ) <EOL> cbar . set_ticks ( clevs ) <EOL> cbar . ax . tick_params ( labelsize = <NUM_LIT:6> ) <EOL> cbar . ax . xaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> cbar . ax . yaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> fig . savefig ( TemporaryFile ( ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> ymax = <NUM_LIT:0> <EOL> for ax in grid : <EOL> bbox = ax . get_position ( ) <EOL> ymax = max ( ymax , bbox . ymax ) <EOL> fig . suptitle ( ptitle , y = ymax + <NUM_LIT> , fontsize = <NUM_LIT:16> ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> def draw_portrait_diagram ( results , rowlabels , collabels , fname , fmt = '<STR_LIT>' , <EOL> gridshape = ( <NUM_LIT:1> , <NUM_LIT:1> ) , xlabel = '<STR_LIT>' , ylabel = '<STR_LIT>' , clabel = '<STR_LIT>' , <EOL> ptitle = '<STR_LIT>' , subtitles = None , cmap = None , clevs = None , <EOL> nlevs = <NUM_LIT:10> , extend = '<STR_LIT>' , aspect = None ) : <EOL> '''<STR_LIT>''' <EOL> if results . ndim == <NUM_LIT:2> : <EOL> results = results . reshape ( <NUM_LIT:1> , * results . shape ) <EOL> nplots = results . shape [ <NUM_LIT:0> ] <EOL> gridshape = _best_grid_shape ( nplots , gridshape ) <EOL> prows , pcols = results . shape [ <NUM_LIT:1> : ] <EOL> if len ( rowlabels ) != prows or len ( collabels ) != pcols : <EOL> raise ValueError ( '<STR_LIT>' % ( prows , pcols ) ) <EOL> width , height = _fig_size ( gridshape ) <EOL> fig = plt . figure ( ) <EOL> fig . set_size_inches ( ( width , height ) ) <EOL> fig . dpi = <NUM_LIT> <EOL> grid = ImageGrid ( fig , <NUM_LIT> , <EOL> nrows_ncols = gridshape , <EOL> axes_pad = <NUM_LIT> , <EOL> share_all = True , <EOL> aspect = False , <EOL> add_all = True , <EOL> ngrids = nplots , <EOL> label_mode = '<STR_LIT:all>' , <EOL> cbar_mode = '<STR_LIT>' , <EOL> cbar_location = '<STR_LIT>' , <EOL> cbar_size = <NUM_LIT> , <EOL> cbar_pad = '<STR_LIT>' <EOL> ) <EOL> if clevs is None : <EOL> clevs = _nice_intervals ( results , nlevs ) <EOL> extend = '<STR_LIT>' <EOL> cmap = plt . get_cmap ( cmap ) <EOL> norm = mpl . colors . BoundaryNorm ( clevs , cmap . N ) <EOL> for i , ax in enumerate ( grid ) : <EOL> data = results [ i ] <EOL> cs = ax . matshow ( data , cmap = cmap , aspect = '<STR_LIT>' , origin = '<STR_LIT>' , norm = norm ) <EOL> ax . xaxis . set_ticks ( np . arange ( data . shape [ <NUM_LIT:1> ] + <NUM_LIT:1> ) ) <EOL> ax . yaxis . set_ticks ( np . arange ( data . shape [ <NUM_LIT:0> ] + <NUM_LIT:1> ) ) <EOL> x = ( ax . xaxis . get_majorticklocs ( ) - <NUM_LIT> ) <EOL> y = ( ax . yaxis . get_majorticklocs ( ) - <NUM_LIT> ) <EOL> ax . vlines ( x , y . min ( ) , y . max ( ) ) <EOL> ax . hlines ( y , x . min ( ) , x . max ( ) ) <EOL> ax . xaxis . tick_bottom ( ) <EOL> ax . xaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> ax . yaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> ax . set_xticklabels ( collabels , fontsize = '<STR_LIT>' ) <EOL> ax . set_yticklabels ( rowlabels , fontsize = '<STR_LIT>' ) <EOL> if subtitles is not None : <EOL> ax . text ( <NUM_LIT:0.5> , <NUM_LIT> , subtitles [ i ] , va = '<STR_LIT>' , ha = '<STR_LIT>' , <EOL> transform = ax . transAxes , fontsize = '<STR_LIT>' ) <EOL> fax = fig . add_subplot ( <NUM_LIT> , frameon = False ) <EOL> fax . tick_params ( labelcolor = '<STR_LIT:none>' , top = '<STR_LIT>' , bottom = '<STR_LIT>' , left = '<STR_LIT>' , right = '<STR_LIT>' ) <EOL> fax . set_ylabel ( ylabel ) <EOL> fax . set_title ( ptitle , fontsize = <NUM_LIT:16> ) <EOL> fax . title . set_y ( <NUM_LIT> ) <EOL> cax = ax . cax <EOL> cbar = fig . colorbar ( cs , cax = cax , norm = norm , boundaries = clevs , drawedges = True , <EOL> extend = extend , orientation = '<STR_LIT>' , extendfrac = '<STR_LIT>' ) <EOL> cbar . set_label ( clabel ) <EOL> cbar . set_ticks ( clevs ) <EOL> cbar . ax . tick_params ( labelsize = <NUM_LIT:6> ) <EOL> cbar . ax . xaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> cbar . ax . yaxis . set_ticks_position ( '<STR_LIT:none>' ) <EOL> cax . set_title ( xlabel , fontsize = <NUM_LIT:12> ) <EOL> cax . title . set_y ( <NUM_LIT> ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) <EOL> fig . clf ( ) <EOL> class TaylorDiagram ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , refstd , radmax = <NUM_LIT> , fig = None , rect = <NUM_LIT> , label = '<STR_LIT:_>' ) : <EOL> """<STR_LIT>""" <EOL> from matplotlib . projections import PolarAxes <EOL> import mpl_toolkits . axisartist . floating_axes as FA <EOL> import mpl_toolkits . axisartist . grid_finder as GF <EOL> self . refstd = refstd <EOL> tr = PolarAxes . PolarTransform ( ) <EOL> rlocs = np . concatenate ( ( np . arange ( <NUM_LIT:10> ) / <NUM_LIT> , [ <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> tlocs = np . arccos ( rlocs ) <EOL> gl1 = GF . FixedLocator ( tlocs ) <EOL> tf1 = GF . DictFormatter ( dict ( zip ( tlocs , map ( str , rlocs ) ) ) ) <EOL> self . smin = <NUM_LIT:0> <EOL> self . smax = radmax * self . refstd <EOL> ghelper = FA . GridHelperCurveLinear ( tr , <EOL> extremes = ( <NUM_LIT:0> , np . pi / <NUM_LIT:2> , <EOL> self . smin , self . smax ) , <EOL> grid_locator1 = gl1 , <EOL> tick_formatter1 = tf1 , <EOL> ) <EOL> if fig is None : <EOL> fig = plt . figure ( ) <EOL> ax = FA . FloatingSubplot ( fig , rect , grid_helper = ghelper ) <EOL> fig . add_subplot ( ax ) <EOL> ax . axis [ "<STR_LIT>" ] . set_axis_direction ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT>" ] . toggle ( ticklabels = True , label = True ) <EOL> ax . axis [ "<STR_LIT>" ] . major_ticklabels . set_axis_direction ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT>" ] . label . set_axis_direction ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT>" ] . label . set_text ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT:left>" ] . set_axis_direction ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT:left>" ] . label . set_text ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT:right>" ] . set_axis_direction ( "<STR_LIT>" ) <EOL> ax . axis [ "<STR_LIT:right>" ] . toggle ( ticklabels = True ) <EOL> ax . axis [ "<STR_LIT:right>" ] . major_ticklabels . set_axis_direction ( "<STR_LIT:left>" ) <EOL> ax . axis [ "<STR_LIT>" ] . set_visible ( False ) <EOL> ax . grid ( False ) <EOL> self . _ax = ax <EOL> self . ax = ax . get_aux_axes ( tr ) <EOL> l , = self . ax . plot ( [ <NUM_LIT:0> ] , self . refstd , '<STR_LIT>' , <EOL> ls = '<STR_LIT>' , ms = <NUM_LIT:10> , label = label ) <EOL> t = np . linspace ( <NUM_LIT:0> , np . pi / <NUM_LIT:2> ) <EOL> r = np . zeros_like ( t ) + self . refstd <EOL> self . ax . plot ( t , r , '<STR_LIT>' , label = '<STR_LIT:_>' ) <EOL> self . samplePoints = [ l ] <EOL> def add_sample ( self , stddev , corrcoef , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> l , = self . ax . plot ( np . arccos ( corrcoef ) , stddev , <EOL> * args , ** kwargs ) <EOL> self . samplePoints . append ( l ) <EOL> return l <EOL> def add_rms_contours ( self , levels = <NUM_LIT:5> , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> rs , ts = np . meshgrid ( np . linspace ( self . smin , self . smax ) , <EOL> np . linspace ( <NUM_LIT:0> , np . pi / <NUM_LIT:2> ) ) <EOL> rms = np . sqrt ( self . refstd ** <NUM_LIT:2> + rs ** <NUM_LIT:2> - <NUM_LIT:2> * self . refstd * rs * np . cos ( ts ) ) <EOL> contours = self . ax . contour ( ts , rs , rms , levels , ** kwargs ) <EOL> def add_stddev_contours ( self , std , corr1 , corr2 , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> t = np . linspace ( np . arccos ( corr1 ) , np . arccos ( corr2 ) ) <EOL> r = np . zeros_like ( t ) + std <EOL> return self . ax . plot ( t , r , '<STR_LIT>' , linewidth = <NUM_LIT:2> ) <EOL> def add_contours ( self , std1 , corr1 , std2 , corr2 , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> t = np . linspace ( np . arccos ( corr1 ) , np . arccos ( corr2 ) ) <EOL> r = np . linspace ( std1 , std2 ) <EOL> return self . ax . plot ( t , r , '<STR_LIT>' , linewidth = <NUM_LIT:2> ) <EOL> def draw_histogram ( dataset_array , data_names , fname , fmt = '<STR_LIT>' , nbins = <NUM_LIT:10> ) : <EOL> '''<STR_LIT>''' <EOL> fig = plt . figure ( ) <EOL> fig . dpi = <NUM_LIT> <EOL> ndata = len ( dataset_array ) <EOL> data_min = <NUM_LIT> <EOL> data_max = <NUM_LIT:0.> <EOL> for data in dataset_array : <EOL> data_min = np . min ( [ data_min , data . min ( ) ] ) <EOL> data_max = np . max ( [ data_max , data . max ( ) ] ) <EOL> bins = np . linspace ( np . round ( data_min ) , np . round ( data_max + <NUM_LIT:1> ) , nbins ) <EOL> for idata , data in enumerate ( dataset_array ) : <EOL> ax = fig . add_subplot ( ndata , <NUM_LIT:1> , idata + <NUM_LIT:1> ) <EOL> ax . hist ( data , bins , alpha = <NUM_LIT:0.5> , label = data_names [ idata ] , normed = True ) <EOL> leg = ax . legend ( ) <EOL> leg . get_frame ( ) . set_alpha ( <NUM_LIT:0.5> ) <EOL> ax . set_xlim ( [ data_min - ( data_max - data_min ) * <NUM_LIT> , data_max + ( data_max - data_min ) * <NUM_LIT> ] ) <EOL> fig . savefig ( '<STR_LIT>' % ( fname , fmt ) , bbox_inches = '<STR_LIT>' , dpi = fig . dpi ) </s>
