Changeset 1147 in lmdz_wrf for trunk/tools/drawing_tools.py
- Timestamp:
- Oct 6, 2016, 3:04:05 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r1134 r1147 1850 1850 elif u == 'ms-2': lu='$ms^{-2}$' 1851 1851 elif u == 'minutes': lu='$minute$' 1852 elif u == 'meters MSL': lu='$m$' 1853 elif u == 'none': lu='-' 1852 1854 elif u == 'Pa/s': lu='$Pas^{-1}$' 1853 1855 elif u == 'Pas-1': lu='$Pas^{-1}$' … … 2709 2711 rangegrph = np.zeros((2), dtype=np.float) 2710 2712 # Changing limits of the colors 2711 if type(vrng[0]) != type(np.float(1.)) and type(vrng[0]) != type(np.float64(1.)):2713 if vrng[0][0:1] == 'S': 2712 2714 if vrng[0] == 'Srange': 2713 2715 rangegrph[0] = np.min(varsV) … … 2765 2767 print ' ' + fname + ': modified shadow min,max:',rangegrph 2766 2768 else: 2767 rangegrph[0] = vrng[0]2768 rangegrph[1] = vrng[1]2769 rangegrph[0] = np.float(vrng[0]) 2770 rangegrph[1] = np.float(vrng[1]) 2769 2771 2770 2772 return rangegrph … … 4443 4445 return 4444 4446 4445 def plot_2D_shadow_contour(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn, \ 4446 colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv): 4447 def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv, \ 4448 yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig, \ 4449 reva, mapv, ifclose): 4447 4450 """ Adding labels and other staff to the graph 4448 4451 varsv= 2D values to plot with shading … … 4451 4454 dim[x/y]v = values at the axes of x and y 4452 4455 dim[x/y]u = units at the axes of x and y 4456 xaxv= list with the x-axis paramteres [style, format, number and orientation] 4457 yaxv= list with the y-axis paramteres [style, format, number and orientation] 4453 4458 dimn= dimension names to plot 4454 4459 colorbar= name of the color bar to use 4460 cbarfmt= format of the numbers in the colorbar 4461 cbaror= orientation of the colorbar 4455 4462 ckind= contour kind 4456 4463 'cmap': as it gets from colorbar … … 4477 4484 * 'h', high 4478 4485 * 'f', full 4486 ifclose= boolean value whether figure should be close (finish) or not 4479 4487 """ 4480 4488 ## import matplotlib as mpl … … 4488 4496 quit() 4489 4497 4498 if len(varsv.shape) != 2: 4499 print errormsg 4500 print ' ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!' 4501 quit(-1) 4502 if len(varcv.shape) != 2: 4503 print errormsg 4504 print ' ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!' 4505 quit(-1) 4506 4507 # Axis ticks 4490 4508 # Usually axis > x must be the lon, thus... 4491 4509 dimxv0 = dimxv.copy() 4492 4510 dimyv0 = dimyv.copy() 4493 dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10)) 4494 dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10)) 4511 4512 dxn = dimxv.min() 4513 dxx = dimxv.max() 4514 dyn = dimyv.min() 4515 dyx = dimyv.max() 4516 4517 if xaxv[0] == 'pretty': 4518 dimxt0 = np.array(pretty_int(dxn,dxx,xaxv[2])) 4519 elif xaxv[0] == 'Nfix': 4520 dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2])) 4521 elif xaxv[0] == 'Vfix': 4522 dimxt0 = np.arange(0,dxx,xaxv[2]) 4523 if yaxv[0] == 'pretty': 4524 dimyt0 = np.array(pretty_int(dyn,dyx,yaxv[2])) 4525 elif yaxv[0] == 'Nfix': 4526 dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2])) 4527 elif yaxv[0] == 'Vfix': 4528 dimyt0 = np.arange(0,dyx,yaxv[2]) 4529 4495 4530 dimxl0 = [] 4496 for i in range(len(dimxt0)): dimxl0.append('{: .1f}'.format(dimxt0[i]))4531 for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1])) 4497 4532 dimyl0 = [] 4498 for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i])) 4533 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1])) 4534 4499 4535 dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')' 4500 4536 dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')' … … 4592 4628 4593 4629 else: 4594 x,y = gen.lonlat2D(dimxv,dimyv) 4630 # No following data values 4631 #x = dimxv 4632 #y = dimyv 4633 x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv)) 4634 y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv)) 4595 4635 4596 4636 plt.rc('text', usetex=True) 4597 4637 4598 4638 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1]) 4599 cbar = plt.colorbar() 4639 if cbaror == 'horizontal': 4640 cbar = plt.colorbar(format=cbarfmt,orientation=cbaror) 4641 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 4642 ticklabels= cbar.ax.get_xticklabels() 4643 Nticks = len(ticklabels) 4644 ticklabs = [] 4645 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 4646 cbar.ax.set_xticklabels(ticklabs,rotation=90) 4647 else: 4648 cbar = plt.colorbar(format=cbarfmt,orientation=cbaror) 4600 4649 4601 4650 # contour … … 4638 4687 plt.ylabel(dimyT) 4639 4688 4640 plt.xticks(dimxt, dimxl )4641 plt.yticks(dimyt, dimyl )4689 plt.xticks(dimxt, dimxl, rotation=xaxv[3]) 4690 plt.yticks(dimyt, dimyl, rotation=yaxv[3]) 4642 4691 4643 4692 # set the limits of the plot to the limits of the data … … 4646 4695 4647 4696 # units labels 4648 cbar.set_label( vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')')4649 plt.annotate( vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' + \4697 cbar.set_label(gen.latex_text(vnames[0]) + ' (' + units_lunits(uts[0]) + ')') 4698 plt.annotate(gen.latex_text(vnames[1]) +' (' + units_lunits(uts[1]) + ') [' + \ 4650 4699 mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction', \ 4651 4700 color=coln) 4652 4701 4653 4702 figname = '2Dfields_shadow-contour' 4654 graphtit = vtit.replace('_','\_').replace('&','\&')4703 graphtit = gen.latex_text(vtit) 4655 4704 4656 4705 plt.title(graphtit) 4657 4706 4658 output_kind(kfig, figname, True)4707 output_kind(kfig, figname, ifclose) 4659 4708 4660 4709 return
Note: See TracChangeset
for help on using the changeset viewer.