Changeset 1937 in lmdz_wrf for trunk/tools/drawing_tools.py
- Timestamp:
- Jul 17, 2018, 3:02:28 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r1936 r1937 1808 1808 """ Function to determine the values for the legend 1809 1809 legstring= char separated list of [locleg][char][fontsize]: 1810 [locleg]: location of the legend (0, aut moatic)1810 [locleg]: location of the legend (0, automatic) 1811 1811 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 1812 1812 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 11497 11497 def plot_SkewT(ta, tda, pres, taxtrm, presxtrm, figtitle, kfig, close): 11498 11498 """ Function to plot a SkewT-logP diagram using matplotlib's API example 11499 ta: air temperature [ K]11500 tda: dew point air temperature [ K]11499 ta: air temperature [C] 11500 tda: dew point air temperature [C] 11501 11501 pres: pessures for ta and tda [Pa] 11502 11502 figtitle: title of figure … … 11581 11581 11582 11582 return 11583 11584 def plot_multi_SkewT(tvals, press, taxtrm, presxtrm, kindgS, kindgv, legv, figtitle, 11585 kfig, close): 11586 """ Function to plot a SkewT-logP diagram with multiple data using matplotlib's 11587 API example 11588 tvals: dictionary with multiple air temperatures [C] 11589 press: dictionary with multiple pessures for ta and tda [Pa] 11590 [kindgS]: kind of graphic to produce. To select from: 11591 'multilines': multiple lines 11592 [kindgv]: dictionary with values for the given [kindgS] 11593 * For 'multilines': 11594 'labels' = list of labels for each line 11595 'collines' = list of colors ('#RRGGBB' values) for each line 11596 'kindmarkers' = list of marker types for each line 11597 'kindlines' = list of line types (matplolib values) of lines 11598 'widthlines' = list of line widths 11599 [legv] = [[locleg], [fontsize]] list with the values for the legend 11600 [locleg]: location of the legend (0, automatic) 11601 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11602 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 11603 9: 'upper center', 10: 'center' 11604 [fontsize]: font size for the legend ('auto' for 12) 11605 figtitle: title of figure 11606 kfig: kind of graphical output (jpg, pdf, png) 11607 close: whether figure should be closed or not 11608 """ 11609 import skewt 11610 11611 fname = 'plot_SkewT' 11612 11613 # Create a new figure. The dimensions here give a good aspect ratio 11614 fig = plt.figure(figsize=(6.5875, 6.2125)) 11615 ax = fig.add_subplot(111, projection='skewx') 11616 11617 plt.grid(True) 11618 11619 # Quantity of dryadiabats 11620 xmax = taxtrm[1] 11621 xmin = taxtrm[0] 11622 print 'len:', np.arange(xmin,xmax,10.) 11623 if len(np.arange(xmin,xmax,10.)) < 10: xfrqtk = 10. 11624 else: xfrqtk = 20. 11625 11626 # Including dry adiabats 11627 ddt = int((xmax+xfrqtk-xmin)/xfrqtk) 11628 for itt in range(ddt): 11629 dryt = thetapotct(xmin+itt*xfrqtk, pmin=10000.) 11630 ax.semilogy(dryt[:,1], dryt[:,0]/100., color='#FFCCCC', linewidth=0.75) 11631 11632 # Including moist- adiabats 11633 #for itt in range(ddt): 11634 # moist = ethetapotct(xmin+itt*xfrqtk, pmin=10000.) 11635 # if xmin+itt*xfrqtk == 10.: print moist[:,1], moist[:,0]/100. 11636 # ax.semilogy(moist[:,1], moist[:,0]/100., color='#CCFFCC', linewidth=0.75) 11637 11638 # An example of a slanted line at constant X 11639 l = ax.axvline(0, color='C0') 11640 11641 Nlines = len(kindgv['labels']) 11642 11643 for iline in range(Nlines): 11644 ta = tvals[iline] 11645 pres = press[iline] 11646 11647 # line characteristics 11648 lline = kindgv['labels'][iline] 11649 cline = kindgv['collines'][iline] 11650 kmark = kindgv['kindmarkers'][iline] 11651 kline = kindgv['kindlines'][iline] 11652 wline = kindgv['widthlines'][iline] 11653 11654 # Checking for variable consistency 11655 if len(ta.shape) != 1: 11656 print errormsg 11657 print ' ' + fname + ": values of 'T[" + str(iline) + "]' must have " + \ 11658 "1D-rank!!" 11659 print ' passed shape:', ta.shape 11660 quit(-1) 11661 if len(pres.shape) != 1: 11662 print errormsg 11663 print ' ' +fname+ ": values of 'pres[" + str(iline) + "]' must have " + \ 11664 "1D-rank!!" 11665 print ' passed shape:', pres.shape 11666 quit(-1) 11667 11668 # Plot the data using normal plotting functions, in this case using 11669 # log scaling in Y, as dictated by the typical meteorological plot 11670 tamask = ta.mask 11671 11672 if lline != 'None': 11673 ax.semilogy(ta.compressed(), pres[~tamask], kline, color=cline, \ 11674 linewidth=wline, marker=kmark, label=lline) 11675 else: 11676 ax.semilogy(ta.compressed(), pres[~tamask], kline, color=cline, \ 11677 linewidth=wline, marker=kmark) 11678 11679 # Disables the log-formatting that comes with semilogy 11680 ax.yaxis.set_major_formatter(ScalarFormatter()) 11681 ax.yaxis.set_minor_formatter(NullFormatter()) 11682 ax.set_yticks(np.linspace(100, 1000, 10)) 11683 ax.set_ylim(presxtrm[1], presxtrm[0]) 11684 11685 ax.xaxis.set_major_locator(MultipleLocator(10)) 11686 ax.set_xlim(taxtrm[0], taxtrm[1]) 11687 11688 # Indices 11689 #plt.annotate('CAPE: ' + str(stvals['CAPE']), xy=(0.98,0.97), \ 11690 # xycoords='axes fraction', ha="right", backgroundcolor='#DDDDDD') 11691 #plt.annotate('CI: '+ str(stvals['CI']), xy=(0.98,0.93), xycoords='axes fraction', \ 11692 # ha='right', backgroundcolor='#DDDDDD') 11693 11694 plt.legend(loc=legv[0], prop={'size':legv[1]}) 11695 11696 ax.set_title(gen.latex_text(figtitle)) 11697 11698 figname = 'multi_SkewT' 11699 output_kind(kfig, figname, close) 11700 11701 return
Note: See TracChangeset
for help on using the changeset viewer.