- Timestamp:
- Jan 28, 2016, 1:38:11 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r684 r687 1813 1813 ncfilens= [filen] ',' separated list of netCDF files 1814 1814 values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg]; 1815 [graphk];[collines];[points];[ pointfreq];[period]1815 [graphk];[collines];[points];[linewidths];[pointsizes];[pointfreq];[period] 1816 1816 [dimvname]: ',' list of names of the variables with he values of the common dimension 1817 1817 [valuesaxis]: which axis will be used for the values ('x', or 'y') … … 1841 1841 [points]: ',' list of type of points for the lines, None for automatic, single 1842 1842 value all the same 1843 [linewidths]: ',' list of widths for the lines, None for automatic, single 1844 value all the same 1845 [pointsizes]: ',' list of widths for the lines, None for automatic, single 1846 value all the same 1843 1847 [pointfreq]: frequency of point plotting, 'all' for all time steps 1844 1848 [period]: which period to plot … … 1858 1862 expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];' 1859 1863 expectargs = expectargs + '[timevals];[locleg];[graphk];[lines];[collines];[points];' 1860 expectargs = expectargs + '[ pointfreq];[period]'1864 expectargs = expectargs + '[linewidths];[pointsizes];[pointfreq];[period]' 1861 1865 drw.check_arguments(fname,len(expectargs.split(';')),values,';',expectargs) 1862 1866 … … 1874 1878 collines0 = values.split(';')[10] 1875 1879 points0 = values.split(';')[11] 1876 pointfreq0 = values.split(';')[12] 1877 period = values.split(';')[13] 1880 linewidths0 = values.split(';')[12] 1881 pointsizes0 = values.split(';')[13] 1882 pointfreq0 = values.split(';')[14] 1883 period = values.split(';')[15] 1878 1884 1879 1885 Nfiles = len(ncfiles) … … 1904 1910 if collines0.find(',') != -1: 1905 1911 collines = collines0.split(',') 1906 elif collines == 'None':1912 elif collines0 == 'None': 1907 1913 collines = None 1908 1914 else: … … 1920 1926 for ip in range(Nfiles): 1921 1927 points.append(points0) 1928 1929 # Multiple line sizes? 1930 if linewidths0.find(',') != -1: 1931 linewidths = [] 1932 Nlines = len(linewidths0.split(',')) 1933 for il in Nlines: 1934 linewidths.append(np.float(linewidths0.split(',')[il])) 1935 elif linewidths0 == 'None': 1936 linewidths = None 1937 else: 1938 linewidths = [np.float(linewidths0)] 1939 1940 # Multiple point sizes? 1941 if pointsizes0.find(',') != -1: 1942 pointsizes = [] 1943 Npts = len(pointsizes0.split(',')) 1944 for ip in Npts: 1945 pointsizes.append(np.float(pointsizes0.split(',')[ip])) 1946 elif pointsizes0 == 'None': 1947 pointsizes = None 1948 else: 1949 pointsizes = [np.float(pointsizes0)] 1922 1950 1923 1951 # Getting values … … 2062 2090 drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, legvals, vartit, \ 2063 2091 varunits, timepos, timelabels, title, locleg, graphk, lines, collines, points, \ 2064 pointfreq)2092 linewidths, pointsizes, pointfreq) 2065 2093 2066 2094 return -
trunk/tools/drawing_tools.py
r684 r687 17 17 fillValueF = 1.e20 18 18 19 colorsauto = ['#FF0000', '#00FF00', '#0000FF', '#FF00FF', '#00FFFF', '#FFAA00', \ 20 '#AA0000', '#00AA00', '#0000AA', '#AA00AA', '#00AAAA', '#AA3200'] 19 21 pointkindsauto = ['.', ',', 'x', '+', '*', '|', '_', 'o', '<', '>', 'v', '^', \ 20 22 's', 'D', 'p' ,'h' ,'H'] 21 23 linekindsauto = ['-', '--', '-.', ':'] 24 linewidthsauto = [1.] 25 pointsizesauto = [7.] 22 26 23 27 ####### Funtions … … 5399 5403 return 5400 5404 5405 def ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq): 5406 """ Function to provide the colors, lines & points styles 5407 Nstyles= total number of styles 5408 colors= list of colors, None for no value 5409 lines= list of lines, None for no value 5410 points= list of points, None for no value 5411 lwidths= list of line widths, None for no value 5412 psizes= list of point sizes, None for no value 5413 ptfreq= frequency for the points, None for all values 5414 >>> Nstyles = 3 5415 >>> colors = ['blue'] 5416 >>> lines = ['-'] 5417 >>> points = ['x', '*', 'o'] 5418 >>> lwidths = ['1'] 5419 >>> psizes = ['2'] 5420 >>> ptfreq = 2 5421 >>> colors, lines, points = ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq) 5422 ['blue', 'blue', 'blue'] 5423 ['-', '-', '-'] 5424 ['x', '*', 'o'] 5425 ['2', '2', '2'] 5426 ['1', '1', '1'] 5427 """ 5428 fname = 'ColorsLinesPointsStyles' 5429 5430 usecolors = [] 5431 uselines = [] 5432 usepoints = [] 5433 usewlines = [] 5434 usespoints = [] 5435 5436 # Colors 5437 if colors is None: 5438 Ncols = len(colorsauto) 5439 for ic in range(Nstyles): 5440 iic = np.mod(ic,Ncols) - 1 5441 if iic == 0: iic = Ncols - 1 5442 usecolors.append(colorsauto[iic]) 5443 else: 5444 Ncols = len(colors) 5445 if Ncols == 1: 5446 for ic in range(Nstyles): 5447 usecolors.append(colors[0]) 5448 else: 5449 if Ncols != Nstyles: 5450 print errormsg 5451 print ' ' + fname + ': number of provided colors:', Ncols, \ 5452 'and required:', Nstyles,'differ !!' 5453 quit(-1) 5454 usecolors = colors 5455 5456 # Lines 5457 if lines is None: 5458 Nklns = len(linekindsauto) 5459 for il in range(Nstyles): 5460 iil = np.mod(il,Nklns) - 1 5461 if iil == 0: iil = Nklns - 1 5462 uselines.append(linekindsauto[iil]) 5463 else: 5464 Nklns = len(lines) 5465 if Nklns == 1: 5466 for il in range(Nstyles): 5467 uselines.append(lines[0]) 5468 else: 5469 if Nklns != Nstyles: 5470 print errormsg 5471 print ' ' + fname + ': number of provided lines:', Nklns, \ 5472 'and required:', Nstyles,'differ !!' 5473 quit(-1) 5474 uselines = lines 5475 5476 # Points 5477 if points is None: 5478 Nkpts = len(pointkindsauto) 5479 for ip in range(Nstyles): 5480 iip = np.mod(ip,Nkpts) - 1 5481 if iip == 0: iip = Nkpts - 1 5482 usepoints.append(pointkindsauto[iip]) 5483 else: 5484 Nkpts = len(points) 5485 if Nkpts == 1: 5486 for ip in range(Nstyles): 5487 usepoints.append(points[0]) 5488 else: 5489 if Nkpts != Nstyles: 5490 print errormsg 5491 print ' ' + fname + ': number of provided points:', Nkpts, \ 5492 'and required:', Nstyles,'differ !!' 5493 quit(-1) 5494 usepoints = points 5495 5496 # Line widths 5497 if lwidths is None: 5498 Nwlns = len(linewidthsauto) 5499 for il in range(Nstyles): 5500 iil = np.mod(il,Nwlns) - 1 5501 if iil == 0: iil = Nwlns - 1 5502 usewlines.append(linewidthsauto[iil]) 5503 else: 5504 Nwlns = len(lwidths) 5505 if Nwlns == 1: 5506 for il in range(Nstyles): 5507 usewlines.append(lwidths[0]) 5508 else: 5509 if Nwlns != Nstyles: 5510 print errormsg 5511 print ' ' + fname + ': number of provided line widthss:', Nwlns, \ 5512 'and required:', Nstyles, 'differ !!' 5513 quit(-1) 5514 usewlines = lwidths 5515 5516 # Point sizes 5517 if psizes is None: 5518 Nspts = len(pointsizesauto) 5519 for ip in range(Nstyles): 5520 iip = np.mod(ip,Nspts) - 1 5521 if iip == 0: iip = Nspts - 1 5522 usespoints.append(pointsizesauto[iip]) 5523 else: 5524 Nspts = len(psizes) 5525 if Nspts == 1: 5526 for ip in range(Nstyles): 5527 usespoints.append(psizes[0]) 5528 else: 5529 if Nspts != Nstyles: 5530 print errormsg 5531 print ' ' + fname + ': number of provided point sizes:', Nspts, \ 5532 'and required:', Nstyles, 'differ !!' 5533 quit(-1) 5534 usespoints = psizes 5535 5536 Ncols = len(usecolors) 5537 Nlins = len(uselines) 5538 Npnts = len(usepoints) 5539 5540 lkinds = [] 5541 pkinds = [] 5542 5543 lcolors = usecolors 5544 5545 # Old way 5546 # if ptfreq is not None: 5547 # lkinds = uselines 5548 # pkinds = usepoints 5549 # else: 5550 # pkinds = usepoints 5551 # lkinds = uselines 5552 # for ilp in range(Nstyles): 5553 # lkinds.append(usepoints[ilp] + uselines[ilp]) 5554 5555 return lcolors, uselines, usepoints, usewlines, usespoints 5556 5557 #Nstyles = 3 5558 #colors = ['blue'] 5559 #lines = ['-'] 5560 #points = ['x', '*', 'o'] 5561 #lwidths = ['2'] 5562 #psizes = ['1'] 5563 #ptfreq = 2 5564 #print ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq) 5565 5401 5566 def LinesPointsStyles(Nstyles, lines, points, ptfreq): 5402 5567 """ Function to provide the lines & points styles … … 5463 5628 pkinds = usepoints 5464 5629 else: 5630 pkinds = usepoints 5465 5631 for ilp in range(Nstyles): 5466 5632 lkinds.append(usepoints[ilp] + uselines[ilp]) … … 5469 5635 5470 5636 def plot_lines_time(vardv, varvv, vaxis, dtit, linesn0, vtit, vunit, tpos, tlabs, \ 5471 gtit, gloc, kfig, lsl, coll, ptl, ptf):5637 gtit, gloc, kfig, lsl, coll, ptl, lwidth, psize, ptf): 5472 5638 """ Function to plot a collection of lines with a time axis 5473 5639 vardv= list of set of dimension values … … 5491 5657 ptl= ',' list of type of points for the lines, None for automatic, single 5492 5658 value all the same 5659 lwidth= ',' list of line widths 5660 psize= ',' list of point sizes 5493 5661 ptf= frequency of point plotting, 'all' for all time steps 5494 5662 5495 5663 plot_lines([np.arange(10)], [np.sin(np.arange(10)*np.pi/2.5)], 'y', 'time (s)', \ 5496 5664 ['2.5'], 'sin', '-', 'sinus frequency dependency', 'pdf') … … 5505 5673 Ntraj = len(vardv) 5506 5674 5507 linekinds, pointkinds = LinesPointsStyles(Ntraj, lsl, ptl, ptf) 5675 colvalues, linekinds, pointkinds, lwidths, psizes = ColorsLinesPointsStyles( \ 5676 Ntraj, coll, lsl, ptl, lwidth, psize, ptf) 5508 5677 5509 5678 plt.rc('text', usetex=True) … … 5522 5691 if vaxis == 'x': 5523 5692 for il in range(Ntraj): 5524 if coll is None: 5525 if ptf is None: 5526 plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il]) 5527 else: 5528 plt.plot(varvv[il], vardv[il], linekinds[il]) 5529 plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il], \ 5530 label= linesn[il]) 5531 else: 5532 if ptf is None: 5533 plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il], \ 5534 color=coll[il]) 5535 else: 5536 plt.plot(varvv[il], vardv[il], linekinds[il], color=coll[il]) 5537 plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il], \ 5538 label= linesn[il], color=coll[il]) 5693 plt.plot(varvv[il], vardv[il], linekinds[il], marker=pointkinds[il], \ 5694 label=linesn[il], color=colvalues[il], linewidth=lwidths[il], \ 5695 markersize=psizes[il], markevery=ptf) 5696 5697 # Old way 5698 # if ptf is None: 5699 # plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il], \ 5700 # color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il]) 5701 # else: 5702 # plt.plot(varvv[il], vardv[il], linekinds[il], color=colvalues[il], \ 5703 # linewidth=lwidths[il]) 5704 # plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il], \ 5705 # label= linesn[il], color=colvalues[il], linewidth=lwidths[il], \ 5706 # markersize=psizes[il]) 5539 5707 5540 5708 minvv = np.min(varvv[il]) … … 5558 5726 else: 5559 5727 for il in range(Ntraj): 5560 if coll is None: 5561 if ptf is None: 5562 plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il]) 5563 else: 5564 plt.plot(vardv[il], varvv[il], linekinds[il]) 5565 plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il], \ 5566 label= linesn[il]) 5567 else: 5568 if ptf is None: 5569 plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il], \ 5570 color=coll[il]) 5571 else: 5572 plt.plot(vardv[il], varvv[il], linekinds[il], color=coll[il]) 5573 plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il], \ 5574 label= linesn[il], color=coll[il]) 5728 plt.plot(vardv[il], varvv[il], linekinds[il], marker=pointkinds[il], \ 5729 label=linesn[il], color=colvalues[il], linewidth=lwidths[il], \ 5730 markersize=psizes[il], markevery=ptf) 5731 5732 # Old way 5733 # if ptf is None: 5734 # plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il], \ 5735 # color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il], markevery=ptf) 5736 # else: 5737 # plt.plot(vardv[il], varvv[il], linekinds[il], color=coll[il], \ 5738 # linewidth=lwidths[il]) 5739 # plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il], \ 5740 # label= linesn[il], color=colvalues[il], linewidth=lwidths[il], \ 5741 # markersize=psizes[il]) 5575 5742 5576 5743 minvv = np.min(varvv[il])
Note: See TracChangeset
for help on using the changeset viewer.