Changeset 1575 in lmdz_wrf
- Timestamp:
- May 13, 2017, 8:53:26 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/documentation/plotting/gallery.html
r1573 r1575 25 25 <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_uw.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 26 26 <A HREF="basins.html"><IMG SRC="figs/basins_named.png" ALT="ORCHIDEE's basin description" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 27 <A HREF="cycle.html"><IMG SRC="figs/cycle_tair_CRUNCEP_spinup_SESA.png" ALT="cicurlar cycle" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 28 <A HREF="cycle.html"><IMG SRC="figs/cycle_tair_CRUNCEP_spinup_SACZ.png" ALT="cicurlar cycle" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 27 29 <A HREF="ensemble_time.html"><IMG SRC="figs/Forcing_pr_spacemean.png" ALT="Ensemble time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 28 30 <A HREF="ensemble_time.html"><IMG SRC="figs/T2_spaceensembleIndiv.png" ALT="Ensemble time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> -
trunk/tools/documentation/plotting/plotting.html
r1559 r1575 20 20 <A CLASS="lc" HREF="barbs.html" TARGET="value">barbs</A><BR> 21 21 <A CLASS="lc" HREF="basins.html" TARGET="value">ORCHIDEE's basins</A><BR> 22 <A CLASS="lc" HREF="cycle.html" TARGET="value">circular cycle</A><BR> 22 23 <A CLASS="lc" HREF="ensemble_time.html" TARGET="value">Ensemble time</A><BR> 23 24 <A CLASS="lc" HREF="Neighbourgh_evol.html" TARGET="value">Neighbourghood evolution</A><BR> -
trunk/tools/drawing.py
r1571 r1575 51 51 ## e.g. # drawing.py -o draw_time_lag -f 'Forcing_rainstats_OKstomate_SESA_norm_meanstd_stat2.nc;time_centered,-1;time_counter;rainnorm%DiPolo_evapstats_SESA_norm_meanstd_OKstomate.nc;time_counter,-1|stats,2;time_counter;evapnorm:Forcing_rainstats_OKstomate_SACZ_norm_meanstd_stat2.nc;time_centered,-1;time_counter;rainnorm%DiPolo_evapstats_SACZ_norm_meanstd_OKstomate.nc;time_counter,-1|stats,2;time_counter;evapnorm' -S 'auto;centered;pr;1;evap;1;-5,5;-2,2;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ;simplepts,1,#AA0000@#0000AA,x,2.;1-month!time-lag!at!SACZ!between!pr!&!evap!normalized!by!mean/stddev;0|12;png;mon1_timelag_pr-evap_SACZ;yes' 52 52 ## e.g. # drawing.py -o draw_ensembles_time -f 'Forcing_rain_SESA.nc;time_counter,-1|stats,0;time_centered;rain_stats;ensemble#Forcing_rain_SESA.nc;time_counter,-1|stats,1;time_centered;rain_stats;ensemble#Forcing_rain_SESA.nc;time_counter,-1|stats,2;time_centered;rain_stats;data' -S 'auto;y;tas;mm/d;auto,auto;#0000FF:-:2.:,:2.;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;FromFile;$pr_{space-mean}^{SESA}$;cloud,#AAAADD,auto;$pr_{space-mean}$!evolution!at!SESA;0|10;png;Forcing_pr_spacemean;no;yes' 53 53 ## e.g. # drawing.py -o draw_cycle -f 'Forcing_tairstats_OKstomate_CRUNCEP_spinup_SESA.nc;time_counter,-1|stats,2;time_centered;tair_stats' -S 'auto;y;centered;tair;K;None;12,3;lines,rainbow,horizontal,auto,-,2.;1,3,5@Sep/Nov,Jan/Jul,Mar/May;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA;year-evolution!of!CRUNCEP!tair!forcing!at!SESA;0|10;png;cycle_tair_CRUNCEP_spinup_SESA;yes' 54 54 55 55 ####### … … 71 71 # draw_barbs: Function to plot wind barbs 72 72 # draw_basins: Function to plot river basins with their discharge vector and basins id (from 'routing.nc') 73 # draw_cycle: Function to plot a variale with a circular cycle 73 74 # draw_ensembles_time: Function to plot an ensembles of data following an axis-time 74 75 # draw_lines: Function to draw different lines at the same time from different files … … 103 104 'draw_2D_shad_line', \ 104 105 'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', \ 105 'draw_bar_time', 'draw_barbs', 'draw_basins', 'draw_ ensembles_time',\106 'draw_bar_time', 'draw_barbs', 'draw_basins', 'draw_cycle', 'draw_ensembles_time', \ 106 107 'draw_2lines', 'draw_2lines_time', 'draw_lines', 'draw_lines_time', \ 107 108 'draw_Neighbourghood_evol', \ … … 8100 8101 return 8101 8102 8103 def draw_cycle(ncfile, values): 8104 """ Function to plot a variale with a circular cycle 8105 ncfile = '#' list of files [filen];[slice];[tvarn];[varn] 8106 [filen]: name of the file 8107 [dimslice]: '|' list of [dimn],[dimrange] 8108 [dimn]: name of the dimension 8109 [dimrange]: range for the slice 8110 * [integer]: which value of the dimension 8111 * -1: all along the dimension 8112 * -9: last value of the dimension 8113 * [beg]@[end]@[inc] slice from [beg] to [end] every [inc] 8114 * NOTE, no dim name all the dimension size 8115 [tvarn]: name of the variable time ('WRFtime', for times from WRF) 8116 [varn]: name of the variable to use for the values 8117 values = [dimxyfmt];[valaxis];[axeskind];[axislab];[axisunits];[rangevals];[cyclevals];[figcyckind]; 8118 [cycticks];[timevals];[labels];[graphtit];[legvalues];[kindfig];[fign];[outfile];[close] 8119 [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordy]: format of the values at each 8120 axis (or single 'auto' for 'auto','auto') 8121 [dxs]: style of x-axis ('auto' for 'pretty') 8122 'Nfix', values computed at even 'Ndx' 8123 'Stringlist', a given list of strings 8124 'Vfix', values computed at even 'Ndx' increments 8125 'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10) 8126 [dxf]: format of the labels at the x-axis 8127 [Ndx]: Number of ticks at the x-axis (for 'Stringlist', '@' list of labels) 8128 [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal) 8129 [dys]: style of y-axis ('auto' for 'pretty') 8130 [dyf]: format of the labels at the y-axis 8131 [Ndy]: Number of ticks at the y-axis 8132 [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal) 8133 [valaxis]: which axes should be used for the data 8134 [axeskind]: type of axes to be plotted 8135 'centered': crossed at 0,0 at the center of the figure 8136 'box': around the figure 8137 [axislab]: Label for the values-axis ('!' for spaces) 8138 [axisunits]: units of the values-label 8139 [rangevals]: Range of the axis with the values (single 'None' for 'auto','auto') 8140 [val1],[val2]: tacking the provided ',' separated list of desired [val1] and [val2] 8141 'auto': automatically set up range using minv and maxv 8142 'extremescentered': extremes automatically centered on zero by computing from data -absmax, absmax; 8143 absmax=max(abs(minval),maxval) 8144 'meancentered': extremes automatically centered on mean by computing from data minv+meanv, maxv-meanv; 8145 meanv=(minval + maxval)/2. 8146 [cyclevals] = [cycle],[cycle0] 8147 [cycle]= numbers of time steps to use for the cycle 8148 [cycle0]= initial position of time steps whithin the cycle 8149 [figcyckind]=[kindname],[valueskind] kind of cycle plot 8150 'cloud',[color]: values as a cloud of points 8151 [color]: name of the colorbar to use changing after the end of each cycle ('auto' for 'rainbow') 8152 'lines',[color],[width],[type]: values a continuous line 8153 [color]: name of the colorbar to use changing after the end of each cycle ('auto' for 'rainbow') 8154 [width]: width of the line to use for all lines ('auto' for 0.5) 8155 [type]: type of the line to use for all lines ('auto' for '-') 8156 [cycticks]= [cycpos]@[cyclab] characteristics of the ticks for the cycle 8157 [cycpos]: ',' list of positions for the ticks (less than cycle/2) 8158 [cyclab]: ',' list of labels for the ticks (less than cycle/2) 8159 [timevals]: [timen]|[units]|[kind]|[tfmt] time labels characteristics 8160 [timen]; name of the time variable 8161 [units]; units string according to CF conventions ([tunits] since 8162 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) 8163 [kind]; kind of output 8164 'Nval': according to a given number of values as 'Nval',[Nval] 8165 'exct': according to an exact time unit as 'exct',[tunit]; 8166 tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month, 8167 'w': week, 'd': day, 'h': hour, 'i': minute, 's': second, 8168 'l': milisecond 8169 [tfmt]; desired format 8170 [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces) 8171 [graphtit]: title of the figure '!' for spaces 8172 [legvalues]=[locleg]|[fontsize]: 8173 [locleg]: location of the legend (0, autmoatic) 8174 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 8175 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 8176 9: 'upper center', 10: 'center' 8177 [fontsize]: font size for the legend (auto for 12) 8178 [kindfig]: kind of output figure (png, pdf, ps) 8179 [fign]: name of the figure (without extension) 8180 [close]: whether figure should be close or not 8181 """ 8182 fname = 'draw_cycle' 8183 8184 if values == 'h': 8185 print fname + '____________________________________________________________' 8186 print draw_cycle.__doc__ 8187 quit() 8188 8189 expectargs = '[dimxyfmt];[valaxis];[axeskind];[axislab];[axisunits];' + \ 8190 '[rangevals];[cyclevals];[figcyckind];[cycticks];[timevals];[labels];'+ \ 8191 '[graphtit];[legvalues];[kindfig];[fign];[close]' 8192 drw.check_arguments(fname,values,expectargs,';') 8193 8194 dimxyfmt = values.split(';')[0] 8195 valaxis = values.split(';')[1] 8196 axiskind = values.split(';')[2] 8197 axislab = values.split(';')[3].replace('!',' ') 8198 axisunits = values.split(';')[4] 8199 rangevals = values.split(';')[5] 8200 cyclevals = values.split(';')[6] 8201 figcyckind = values.split(';')[7] 8202 cycticks = values.split(';')[8].split('@') 8203 timevals = values.split(';')[9] 8204 labels = gen.str_list(values.split(';')[10].replace('!', ' '), ',') 8205 graphtit = values.split(';')[11].replace('!',' ') 8206 legvalues = values.split(';')[12] 8207 kindfig = values.split(';')[13] 8208 fign = values.split(';')[14] 8209 close = gen.Str_Bool(values.split(';')[15]) 8210 8211 # cycle 8212 cycle = int(cyclevals.split(',')[0]) 8213 cycle0 = int(cyclevals.split(',')[1]) 8214 8215 # time-values 8216 expectargs = '[timen]|[units]|[kind]|[tfmt]' 8217 drw.check_arguments('timevals: '+fname,timevals,expectargs,'|') 8218 8219 timen = timevals.split('|')[0].replace('!',' ') 8220 timeunit = timevals.split('|')[1].replace('!',' ') 8221 timekind = timevals.split('|')[2] 8222 timefmt = timevals.split('|')[3] 8223 8224 # files 8225 valfiles = gen.str_list(ncfile, '#') 8226 8227 values = [] 8228 timevalues = [] 8229 8230 mintval = gen.fillValueF 8231 maxtval = -gen.fillValueF 8232 minvval = gen.fillValueF 8233 maxvval = -gen.fillValueF 8234 8235 ifile = 0 8236 dimt = -gen.fillValueF 8237 for fdv in valfiles: 8238 fvals = fdv.split(';') 8239 expectedargs = '[filen];[slice];[tvarn];[varn]' 8240 gen.check_arguments('filevals: '+fname, fdv, expectedargs, ';') 8241 filen = fvals[0] 8242 dimrange = fvals[1] 8243 tvarn = fvals[2] 8244 yvarn = fvals[3] 8245 8246 if not os.path.isfile(filen): 8247 print errormsg 8248 print ' ' + fname + ': file "' + filen + '" does not exist !!' 8249 quit(-1) 8250 8251 onc = NetCDFFile(filen, 'r') 8252 if tvarn == 'WRFtime': 8253 datesv = [] 8254 if tvarn == 'WRFtime': 8255 fdates = onc.variables['Times'][:] 8256 for it in range(fdates.shape[0]): 8257 datesv.append(gen.datetimeStr_conversion(fdates[it,:], \ 8258 'WRFdatetime','cfTime,' + timeunit)) 8259 tvs = np.array(datesv, dtype=np.float) 8260 tunitsvar = timeunit 8261 else: 8262 if not onc.variables.has_key(tvarn): 8263 print errormsg 8264 print ' ' +fname+ ': file "' +filen+ "' does not have variable '" + \ 8265 tvarn + "' for the time-values !!" 8266 print ' available ones:', onc.variables.keys() 8267 onc.close() 8268 quit(-1) 8269 otvar = onc.variables[tvarn] 8270 tvs, tdims = ncvar.slice_variable(otvar, dimrange.replace(',',':')) 8271 tunitsvar = otvar.units 8272 8273 if not onc.variables.has_key(yvarn): 8274 print errormsg 8275 print ' ' +fname+ ': file "' +filen+ "' does not have variable '" + \ 8276 yvarn + "' for the y-values !!" 8277 print ' available ones:', onc.variables.keys() 8278 onc.close() 8279 quit(-1) 8280 8281 oyvar = onc.variables[yvarn] 8282 yvs, ydims = ncvar.slice_variable(oyvar, dimrange.replace(',',':')) 8283 8284 # Referring all times to the same reference time! 8285 reftvals = gen.coincident_CFtimes(tvs, timeunit, tunitsvar) 8286 8287 onc.close() 8288 8289 if len(reftvals) > dimt: dimt = len(reftvals) 8290 8291 reftn = reftvals.min() 8292 reftx = reftvals.max() 8293 if reftn < mintval: mintval = reftn 8294 if reftx > maxtval: maxtval = reftx 8295 refvn = yvs.min() 8296 refvx = yvs.max() 8297 if refvn < minvval: minvval = refvn 8298 if refvx > maxvval: maxvval = refvx 8299 8300 values.append(yvs) 8301 timevalues.append(reftvals) 8302 8303 ifile = ifile + 1 8304 8305 # cycle ticks 8306 pos=cycticks[0].split(',') 8307 ll=cycticks[1].split(',') 8308 ctick = [] 8309 clab = [] 8310 for ip in range(len(pos)): 8311 ctick.append(np.float(pos[ip])) 8312 clab.append(gen.latex_text(ll[ip])) 8313 8314 # Times 8315 dtvals = (maxtval - mintval)/10 8316 dti = mintval 8317 dte = maxtval 8318 tvalsticks = np.arange(dti, dte+dtvals, dtvals) 8319 8320 dtiS = drw.datetimeStr_conversion(str(dti) + ',' + timeunit, 'cfTime', \ 8321 'Y/m/d H-M-S') 8322 dteS = drw.datetimeStr_conversion(str(dte) + ',' + timeunit, 'cfTime', \ 8323 'Y/m/d H-M-S') 8324 8325 print ' ' + fname + ': plotting from: ' + dtiS + ' to ' + dteS 8326 timepos, timelabels = drw.CFtimes_plot(tvalsticks, timeunit, timekind, timefmt) 8327 8328 # ranges 8329 rng = gen.minmax_range(minvval, maxvval, rangevals) 8330 8331 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',') 8332 xaxis = [xstyl, xaxf, Nxax, xaxor] 8333 yaxis = [ystyl, yaxf, Nyax, yaxor] 8334 8335 # Legend 8336 legloc, legsiz = drw.legend_values(legvalues,'|') 8337 8338 drw.plot_cycle(values, timevalues, xaxis, yaxis, valaxis, axiskind, axislab, \ 8339 axisunits, rng, cycle, cycle0, figcyckind, labels, ctick, clab, timen, timepos,\ 8340 timelabels, graphtit, legloc, legsiz, kindfig, fign, close) 8341 8342 return 8343 8102 8344 #quit() 8103 8345 … … 8123 8365 'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time', \ 8124 8366 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time', \ 8125 'draw_ ensembles_time', 'draw_lines',\8367 'draw_cycle', 'draw_ensembles_time', 'draw_lines', \ 8126 8368 'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_time_lag', \ 8127 8369 'draw_topo_geogrid_boxes', \ … … 8192 8434 elif oper == 'draw_basins': 8193 8435 draw_basins(opts.ncfile, opts.values) 8436 elif oper == 'draw_cycle': 8437 draw_cycle(opts.ncfile, opts.values) 8194 8438 elif oper == 'draw_ensembles_time': 8195 8439 draw_ensembles_time(opts.ncfile, opts.values) -
trunk/tools/drawing_tools.py
r1573 r1575 89 89 # plot_bars_time: Function to plot a bar plot with multiple columns with time axis 90 90 # plot_bars_line: Function to plot a bar and lines plot with multiple columns with a time-axis 91 # plot_cycle: Function to plot a variale with a circular cycle 91 92 # plot_lines: Function to plot a collection of lines 92 93 # plot_Taylor: Function to draw a Taylor diagram (Taylor 2001) … … 10419 10420 10420 10421 return 10422 10423 def plot_cycle(vals, tvals, xaxv, yaxv, axkind, axistype, axlab, axunits, axrng, \ 10424 cyc, cyc0, cyck, labs, cycp, cycl, tn, tpos, tlabs, gtit, lloc, lsiz, kfig, fn,\ 10425 ifclose): 10426 """ Function to plot a cycle 10427 vals= list of cyclic values 10428 tvals= list with the time-values 10429 [x/y]axv= values at the axes x and y 10430 axkind= in which axis should the values be plotted ('x', 'y') 10431 axlab= label of the axis values 10432 axunits= units of the axis values 10433 axrng= range of the axis values 10434 cyc= number of time steps of a whole cycle 10435 cyc0= initial position of time steps whithin the cycle 10436 cyck=[kindname],[valueskind] kind of cycle plot 10437 'cloud',[color],[cbaror],[cbarfmt],[marker],[markersize]: values as a cloud of points 10438 [color]: name of the colorbar to use changing after the end of each cycle ('auto' for 'rainbow') 10439 [cbaror]: orientation of the colorbar ('auto' for vertical) 10440 [cbarfmt]: format of the numbers in the colorbar ('auto' for %5.2g) 10441 [marker]: '@' list of kind of marker (single value for the same for all) 10442 [markersize]: '@' list of size of marker (single value for the same for all) 10443 'lines',[color],[width],[type]: values a continuous line 10444 [color]: name of the colorbar to use changing after the end of each cycle ('auto' for 'rainbow') 10445 [width]: width of the line to use for all lines ('auto' for 0.5) 10446 [type]: type of the line to use for all lines ('auto' for '-') 10447 labs= list of labels for legend of lines (None for no legend, and 'None' for no specific label) 10448 cycp= position of the cycle ticks 10449 cycl= labels of the cycle ticks 10450 tn= label of the time-axis 10451 tpos= position of the time-ticks 10452 tlabs= labels of the time-ticks 10453 gtit= title of the figure 10454 lloc= location of the legend (0, autmoatic) 10455 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10456 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 10457 9: 'upper center', 10: 'center' 10458 lsiz= font size of the legend 10459 kfig= kind of output: pdf, png, ps 10460 fn= name of the figure 10461 ifclose= whether figure should be closed 10462 """ 10463 fname = 'plot_cycle' 10464 10465 Nvalues = len(vals) 10466 10467 dyn = axrng[0] 10468 dyx = axrng[1] 10469 10470 axstyles = ['pretty', 'Nfix', 'Stringlist', 'Vfix'] 10471 if yaxv[0] == 'pretty': 10472 dimyt = np.array(gen.pretty_int(dyn,dyx,yaxv[2])) 10473 dimyl = np.array(dimyt, dtype=str) 10474 elif yaxv[0] == 'Nfix': 10475 dimyt = np.arange(dyn,dyx,(dyx-dyn)/(yaxv[2]+1)) 10476 dimyl = np.arange(dyn,dyx,(dyx-dyn)/Lymaxvals) 10477 axytype='fixpixel' 10478 elif yaxv[0] == 'Vfix': 10479 dynvfix = int(dyn/yaxv[2]) 10480 dimyt = np.arange(dynvfix*xaxv[2],dyx,yaxv[2]) 10481 axytype='data' 10482 else: 10483 print errormsg 10484 print ' ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!" 10485 print ' available ones: ', axstyles 10486 quit(-1) 10487 10488 # kind of cycle figure: 10489 figv = cyck.split(',') 10490 figtypen = figv[0] 10491 10492 # Computing cycling x-positions 10493 cycx = [] 10494 for it in range(cyc): 10495 itx = cyc0 + it 10496 if itx <= cyc/2: 10497 cycx.append(itx) 10498 else: 10499 if cyc-itx > 0: 10500 cycx.append(cyc-itx) 10501 else: 10502 cycx.append(np.abs(cyc-itx)) 10503 cycx.append(cyc0) 10504 print ' ' + fname + ': cycle positions:', cycx 10505 10506 plt.rc('text', usetex=True) 10507 fig, ax = plt.subplots(1) 10508 10509 for iv in range(Nvalues): 10510 xvs = vals[iv] 10511 dimt = len(xvs) 10512 Ncyc = dimt/cyc 10513 10514 # Normalizing position of the ticks 10515 if iv == 0: 10516 tminv = np.min(tvals[iv]) 10517 tmaxv = np.max(tvals[iv]) 10518 tpos = tpos*Ncyc/tmaxv 10519 10520 if figtypen == 'cloud': 10521 expectargs = 'cloud,[color],[cbaror],[cbarfmt],[marker],[marekersize]' 10522 check_arguments(fname + " & 'cloud'", cyck, expectargs,',') 10523 10524 colbar = gen.auto_val(figv[1], 'rainbow') 10525 cbaror = gen.auto_val(figv[2], 'vertical') 10526 cbarfmt = gen.auto_val(figv[3], '%5.2g') 10527 mtype = gen.str_list_rep(figv[4],'@',Nvalues) 10528 msize = gen.str_list_rep(figv[5],'@',Nvalues) 10529 10530 my_cmap = plt.cm.get_cmap(colbar) 10531 norm = mpl.colors.Normalize(0.,Ncyc) 10532 10533 if labs is not None and labs[iv] != 'None': 10534 for ic in range(Ncyc): 10535 clv = my_cmap(norm(ic*1.)) 10536 for it in range(cyc): 10537 Tt = cyc*ic+it 10538 if Tt + 1 > dimt-1: break 10539 if ic == 0 and it == 0: 10540 if axkind == 'y': 10541 plt.plot(cycx[it], xvs[Tt], color=clv, marker=mtype[iv], \ 10542 markersize=np.float(msize[iv]), \ 10543 label=gen.latex_text(labs[iv])) 10544 else: 10545 plt.plot(xvs[Tt], cycx[it], color=clv, marker=mtype[iv], \ 10546 markersize=np.float(msize[iv]), \ 10547 label=gen.latex_text(labs[iv])) 10548 else: 10549 if axkind == 'y': 10550 plt.plot(cycx[it], xvs[Tt], color=clv, marker=mtype[iv], \ 10551 markersize=np.float(msize[iv])) 10552 else: 10553 plt.plot(xvs[Tt], cycx[it], color=clv, marker=mtype[iv], \ 10554 markersize=np.float(msize[iv])) 10555 else: 10556 for ip in range(Ncyc): 10557 clv = my_cmap(norm(ip*1.)) 10558 for it in range(cyc): 10559 Tt = cyc*ic+it 10560 if Tt + 1 > dimt-1: break 10561 if axkind == 'y': 10562 plt.plot(cycx[it], xvs[Tt], color=clv, marker=mtype[iv], \ 10563 markersize=np.float(msize[iv])) 10564 else: 10565 plt.plot(xvs[Tt], cycx[it], color=clv, marker=mtype[iv], \ 10566 markersize=np.float(msize[iv])) 10567 10568 # Plotting with lines 10569 elif figtypen == 'lines': 10570 expectargs = 'lines,[color],[cbaror],[cbarfmt],[linetype],[linewidth]' 10571 check_arguments(fname + " & 'cloud'", cyck, expectargs,',') 10572 10573 colbar = gen.auto_val(figv[1], 'rainbow') 10574 cbaror = gen.auto_val(figv[2], 'vertical') 10575 cbarfmt = gen.auto_val(figv[3], '%5.2g') 10576 ltype = gen.str_list_rep(figv[4],'@',Nvalues) 10577 lwdth = gen.str_list_rep(figv[5],'@',Nvalues) 10578 10579 my_cmap = plt.cm.get_cmap(colbar) 10580 tminv = np.min(tvals[iv]) 10581 tmaxv = np.max(tvals[iv]) 10582 norm = mpl.colors.Normalize(0.,Ncyc) 10583 10584 if labs is not None and labs[iv] != 'None': 10585 for ic in range(Ncyc): 10586 clv = my_cmap(norm(ic*1.)) 10587 for it in range(cyc): 10588 Tt = cyc*ic+it 10589 if Tt + 1 > dimt-1: break 10590 xl = [cycx[it], cycx[it+1]] 10591 yl = [xvs[Tt], xvs[Tt+1]] 10592 if ic == 0 and it == 0: 10593 if axkind == 'y': 10594 plt.plot(xl, yl, ltype[iv], color=clv, \ 10595 linewidth=np.float(lwdth[iv]), \ 10596 label=gen.latex_text(labs[iv])) 10597 else: 10598 plt.plot(yl, xl, marker=ltype[iv], color=clv, \ 10599 linewidth=np.float(lwdth[iv]), \ 10600 label=gen.latex_text(labs[iv])) 10601 else: 10602 if axkind == 'y': 10603 plt.plot(xl, yl, ltype[iv], color=clv, \ 10604 linewidth=np.float(lwdth[iv])) 10605 else: 10606 plt.plot(yl, xl, ltype[iv], color=clv, \ 10607 linewidth=np.float(lwdth[iv])) 10608 else: 10609 for ip in range(Ncyc): 10610 clv = my_cmap(norm(ip*1.)) 10611 for it in range(cyc): 10612 Tt = cyc*ic+it 10613 if Tt + 1 > dimt-1: break 10614 xl = [cycx[it], cycx[it+1]] 10615 yl = [xvs[Tt], xvs[Tt+1]] 10616 if axkind == 'y': 10617 plt.plot(xl, yl, ltype[iv], color=clv, \ 10618 linewidth=np.float(lwdth[iv])) 10619 else: 10620 plt.plot(yl, xl, ltype[iv], color=clv, \ 10621 linewidth=np.float(lwdth[iv])) 10622 else: 10623 print errormsg 10624 print ' ' + fname + ": cycle figure named '" + figtypen + "' not reay !!" 10625 print ' availabe ones:', ['cloud', 'lines'] 10626 quit(-1) 10627 10628 if axistype == 'box': 10629 print gen.infmsg 10630 print ' ' + fname + ': plotting with around axes' 10631 elif axistype == 'centered': 10632 # Drawing centered axes 10633 # From http://stackoverflow.com/questions/31556446/drawing-axis-in-the-midde-of-the-figue-in-python 10634 # Move left y-axis and bottim x-axis to centre, passing through (0,0) 10635 ax.spines['left'].set_position('center') 10636 ax.spines['bottom'].set_position('center') 10637 10638 # Eliminate upper and right axes 10639 ax.spines['right'].set_color('none') 10640 ax.spines['top'].set_color('none') 10641 10642 ax.xaxis.set_label_coords(0.5, -0.025) 10643 ax.yaxis.set_label_coords(-0.025, 0.5) 10644 10645 else: 10646 print errormsg 10647 print ' ' + fname + ": axis plotting type '" + axistype + "' not ready !!" 10648 print ' available ones:', ['box', 'centered'] 10649 quit(-1) 10650 10651 if axkind == 'y': 10652 plt.xticks(cycp, cycl, rotation=xaxv[3]) 10653 plt.yticks(dimyt, list(dimyl), rotation=yaxv[3]) 10654 if axunits != 'None': 10655 plt.ylabel(gen.latex_text(axlab) + ' (' + units_lunits(axunits) + ')') 10656 else: 10657 plt.ylabel(gen.latex_text(axlab)) 10658 plt.xlim(-1., cyc/2.+1) 10659 plt.ylim(axrng[0], axrng[1]) 10660 else: 10661 plt.xticks(dimyt, list(dimyl), rotation=yaxv[3]) 10662 plt.yticks(cycp, cycl, rotation=xaxv[3]) 10663 if axunits != 'None': 10664 plt.xlabel(gen.latex_text(axlab) + ' (' + units_lunits(axunits) + ')') 10665 else: 10666 plt.xlabel(gen.latex_text(axlab)) 10667 plt.xlim(axrng[0], axrng[1]) 10668 plt.ylim(-1., cyc/2.+1) 10669 10670 if labs is not None: 10671 plt.legend(loc=lloc, prop={'size':lsiz}) 10672 10673 # Colorbar 10674 if gen.searchInlist(['cloud', 'lines'], figtypen): 10675 # FROM: http://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots 10676 # For matplotlib v1.3 or greater the code becomes: 10677 sm = plt.cm.ScalarMappable(cmap=colbar, norm=norm) 10678 # fake up the array of the scalar mappable. Urgh... 10679 sm._A = [] 10680 #cbar = plt.colorbar(sm) 10681 10682 if cbaror == 'horizontal': 10683 cbar = plt.colorbar(sm, ticks=[tpos], format=cbarfmt, orientation=cbaror) 10684 cbar.ax.set_xticklabels(tlabs,rotation=90) 10685 else: 10686 print warnmsg 10687 print ' ' + fname + ": This is odd, because in 'vertical' mode does " + \ 10688 "not work the re-labelling of the ticking!" 10689 cbar = plt.colorbar(sm, ticks=[tpos], format=cbarfmt, orientation=cbaror) 10690 cbar.ax.set_xticklabels(tlabs) 10691 10692 cbar.set_label(gen.latex_text(tn)) 10693 10694 plt.title(gen.latex_text(gtit)) 10695 10696 output_kind(kfig, fn, ifclose) 10697 10698 return
Note: See TracChangeset
for help on using the changeset viewer.