- Timestamp:
- Feb 23, 2021, 1:21:52 PM (4 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2775 r2852 11316 11316 [fontsize]: font size for the legend (auto for 12) 11317 11317 [Ncol]: number of columns (1) 11318 labels: labels to write in the graph ('!' for spaces )11318 labels: labels to write in the graph ('!' for spaces, '*' for no label) 11319 11319 boxlvals: [line style]|[line width] values for the boxes (['-', 3], auto) 11320 11320 [ColorLeg] = [ijstart, orientation, labsize, sqsize, labrotation, … … 11442 11442 Boxlvals = ['-', 3] 11443 11443 11444 if ColorLeg != 'auto': 11445 colorleg = [np.float(ColorLeg.split('|')[0]), ColorLeg.split('|')[1], \ 11446 np.float(ColorLeg.split('|')[2]), np.float(ColorLeg.split('|')[3]), \ 11447 np.float(ColorLeg.split('|')[4]), np.float(ColorLeg.split('|')[5]), \ 11448 np.float(ColorLeg.split('|')[6]), ColorLeg.split('|')[7]] 11449 else: 11450 colorleg = [0.8, 'vertical', 10., 10., 0., 0.8, 0.1, '#CCCCFF'] 11444 if ColorLeg == 'None': 11445 colorleg = [None]*7 + ['#CCCCFF'] 11446 else: 11447 if ColorLeg != 'auto': 11448 colorleg = [np.float(ColorLeg.split('|')[0]), ColorLeg.split('|')[1], \ 11449 np.float(ColorLeg.split('|')[2]), np.float(ColorLeg.split('|')[3]), \ 11450 np.float(ColorLeg.split('|')[4]), np.float(ColorLeg.split('|')[5]), \ 11451 np.float(ColorLeg.split('|')[6]), ColorLeg.split('|')[7]] 11452 else: 11453 colorleg = [0.8, 'vertical', 10., 10., 0., 0.8, 0.1, '#CCCCFF'] 11451 11454 11452 11455 if mervals != 'auto': -
trunk/tools/drawing_tools.py
r2848 r2852 2731 2731 # Trimming figures 2732 2732 # FROM: https://stackoverflow.com/questions/3130072/matplotlib-savefig-image-trim 2733 plt.tight_layout()2733 #plt.tight_layout() 2734 2734 2735 2735 if close: … … 14631 14631 landseamask= landseamask values of the first domain 14632 14632 boxesX/Y= 4-line sets to draw the boxes 14633 boxlabels= labels for the legend of the boxes 14633 boxlabels= labels for the legend of the boxes ('*' for no label) 14634 14634 o[lon/lat]= longitude and latitude objects 14635 14635 lonlatLims: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] … … 14753 14753 bbcol = gen.modify_color(cols[ibox], 'hex', 32, 'darken') 14754 14754 ix, iy = m(boxesX[ibox*4], boxesY[ibox*4]) 14755 plt.plot(ix, iy, linestyle=boxlvals[0], linewidth=boxlvals[1], color=bbcol, \ 14756 label=gen.latex_text(boxlabels[ibox].replace('!',' '))) 14755 if boxlabels[ibox] != '*': 14756 plt.plot(ix, iy, linestyle=boxlvals[0], linewidth=boxlvals[1], \ 14757 color=bbcol, label=gen.latex_text(boxlabels[ibox].replace('!',' '))) 14757 14758 ix, iy = m(boxesX[ibox*4+1], boxesY[ibox*4+1]) 14758 14759 plt.plot(ix, iy, linestyle=boxlvals[0], linewidth=boxlvals[1], color=bbcol) … … 14780 14781 X, Y = fig.get_dpi() * fig.get_size_inches() 14781 14782 14782 # Dimensions of the color-legend 14783 totboxlength = legcolv[5] 14784 ibox = legcolv[6] 14785 14786 cbox = unichr(9632)#+unichr(9632)+unichr(9632) 14787 bbox = unichr(9633) 14788 14789 ccs = np.arange(0.,totboxlength,totboxlength/(nrows+1)) 14790 14791 iix = legcolv[0] 14792 Ns = [] 14793 Cs = [] 14794 Xs = [] 14795 Ys = [] 14796 if legcolv[1] == 'vertical': 14797 bw = totboxlength / (nrows + 1) 14798 bh = bw * X / Y 14799 Ns.append('> ' + str(topobnds[Ncolors-2])) 14800 Cs.append(Ncolors-2) 14801 Xs.append([iix,iix-bh]) 14802 Ys.append(ibox - ccs[0]) 14803 for i in range(1,Ncolors-2): 14804 Ns.append(str(topobnds[Ncolors-2-i])) 14805 Cs.append(Ncolors-2-i) 14783 if legcolv[0] is not None: 14784 # Dimensions of the color-legend 14785 totboxlength = legcolv[5] 14786 ibox = legcolv[6] 14787 14788 cbox = unichr(9632)#+unichr(9632)+unichr(9632) 14789 bbox = unichr(9633) 14790 14791 ccs = np.arange(0.,totboxlength,totboxlength/(nrows+1)) 14792 14793 iix = legcolv[0] 14794 Ns = [] 14795 Cs = [] 14796 Xs = [] 14797 Ys = [] 14798 if legcolv[1] == 'vertical': 14799 bw = totboxlength / (nrows + 1) 14800 bh = bw * X / Y 14801 Ns.append('> ' + str(topobnds[Ncolors-2])) 14802 Cs.append(Ncolors-2) 14806 14803 Xs.append([iix,iix-bh]) 14807 Ys.append(ibox - ccs[ i])14808 Ns.append('< 0')14809 Cs.append(0)14810 Xs.append([iix,iix-bh])14811 Ys.append(ibox - ccs[Ncolors-2])14812 14813 elif legcolv[1] == 'horizontal':14814 bw = totboxlength / (nrows + 1)14815 bh = bw * Y / X14816 14817 Ns.append('< 0') 14818 Cs.append(0)14819 Xs.append(ibox+ccs[0])14820 Ys.append([iix-bh,iix])14821 for i in range(1,Ncolors-2): 14822 Ns.append( str(topobnds[i]))14823 Cs.append( i)14824 Xs.append(ibox + ccs[i])14804 Ys.append(ibox - ccs[0]) 14805 for i in range(1,Ncolors-2): 14806 Ns.append(str(topobnds[Ncolors-2-i])) 14807 Cs.append(Ncolors-2-i) 14808 Xs.append([iix,iix-bh]) 14809 Ys.append(ibox - ccs[i]) 14810 Ns.append('< 0') 14811 Cs.append(0) 14812 Xs.append([iix,iix-bh]) 14813 Ys.append(ibox - ccs[Ncolors-2]) 14814 14815 elif legcolv[1] == 'horizontal': 14816 bw = totboxlength / (nrows + 1) 14817 bh = bw * Y / X 14818 14819 Ns.append('< 0') 14820 Cs.append(0) 14821 Xs.append(ibox+ccs[0]) 14825 14822 Ys.append([iix-bh,iix]) 14826 Ns.append('> ' + str(topobnds[Ncolors-2])) 14827 Cs.append(Ncolors-2) 14828 Xs.append(ibox + ccs[Ncolors-2]) 14829 Ys.append([iix-bh,iix]) 14830 else: 14831 print errormsg 14832 print ' ' + fname + ": oritnation of legend of colors of topography " + \ 14833 "scale '" + legcolv[1] + "' not ready !!" 14834 print ' available ones:', availor 14835 quit(-1) 14836 14837 for ib in range(0,Ncolors-1): 14838 Nb = Ns[ib] 14839 if legcolv[1] == 'vertical': 14840 ix = Xs[ib][0] 14841 iy = Ys[ib] 14842 elif legcolv[1] == 'horizontal': 14843 ix = Xs[ib] 14844 iy = Ys[ib][0] 14845 plt.annotate(Nb, xy=(ix,iy), xycoords='figure fraction', fontsize=legcolv[2],\ 14846 rotation=legcolv[4]) 14847 if legcolv[1] == 'vertical': 14848 ix = Xs[ib][1] 14849 elif legcolv[1] == 'horizontal': 14850 iy = Ys[ib][1] 14851 plt.annotate(cbox, xy=(ix,iy), xycoords='figure fraction', \ 14852 fontsize=legcolv[3], color=HEXtopocolors[Cs[ib]]) 14853 plt.annotate(bbox, xy=(ix,iy), xycoords='figure fraction', \ 14854 fontsize=legcolv[3], color='k') 14823 for i in range(1,Ncolors-2): 14824 Ns.append(str(topobnds[i])) 14825 Cs.append(i) 14826 Xs.append(ibox + ccs[i]) 14827 Ys.append([iix-bh,iix]) 14828 Ns.append('> ' + str(topobnds[Ncolors-2])) 14829 Cs.append(Ncolors-2) 14830 Xs.append(ibox + ccs[Ncolors-2]) 14831 Ys.append([iix-bh,iix]) 14832 else: 14833 print errormsg 14834 print ' ' + fname + ": oritnation of legend of colors of topography " + \ 14835 "scale '" + legcolv[1] + "' not ready !!" 14836 print ' available ones:', availor 14837 quit(-1) 14838 14839 for ib in range(0,Ncolors-1): 14840 Nb = Ns[ib] 14841 if legcolv[1] == 'vertical': 14842 ix = Xs[ib][0] 14843 iy = Ys[ib] 14844 elif legcolv[1] == 'horizontal': 14845 ix = Xs[ib] 14846 iy = Ys[ib][0] 14847 plt.annotate(Nb, xy=(ix,iy), xycoords='figure fraction', \ 14848 fontsize=legcolv[2], rotation=legcolv[4]) 14849 if legcolv[1] == 'vertical': 14850 ix = Xs[ib][1] 14851 elif legcolv[1] == 'horizontal': 14852 iy = Ys[ib][1] 14853 plt.annotate(cbox, xy=(ix,iy), xycoords='figure fraction', \ 14854 fontsize=legcolv[3], color=HEXtopocolors[Cs[ib]]) 14855 plt.annotate(bbox, xy=(ix,iy), xycoords='figure fraction', \ 14856 fontsize=legcolv[3], color='k') 14855 14857 14856 14858 figname = 'plot_topofix_geogrid'
Note: See TracChangeset
for help on using the changeset viewer.