Changeset 1283 in lmdz_wrf for trunk/tools/drawing_tools.py
- Timestamp:
- Nov 8, 2016, 4:54:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r1277 r1283 3021 3021 #quit() 3022 3022 3023 def plot_points(xval, yval, vlon, vlat, extravals, extrapar, vtit, mapv, figk, color,\3024 labels, lloc, kfig, figname):3023 def plot_points(xval, yval, vlon, vlat, extravals, extrapar, vtit, xaxv, yaxv, mapv, \ 3024 figk, color, labels, lloc, kfig, figname, ifclose): 3025 3025 """ plotting points 3026 3026 [x/yval]: x,y values to plot … … 3030 3030 extrapar= [varname, min, max, cbar, varunits] of the extra variable 3031 3031 vtit= title of the graph ('|' for spaces) 3032 xaxv= list with the x-axis paramteres [style, format, number and orientation] 3033 yaxv= list with the y-axis paramteres [style, format, number and orientation] 3032 3034 mapv= map characteristics: [proj],[res] 3033 3035 see full documentation: http://matplotlib.org/basemap/ … … 3049 3051 kfig= kind of figure (jpg, pdf, png) 3050 3052 figname= name of the figure 3051 3053 ifclose= boolean value whether figure should be close (finish) or not 3052 3054 """ 3053 3055 fname = 'plot_points' 3056 3057 # Axis ticks 3058 # Usually axis > x must be the lon, thus... 3059 dimxv0 = np.array(xval) 3060 dimyv0 = np.array(yval) 3061 3062 dxn = dimxv0.min() 3063 dxx = dimxv0.max() 3064 dyn = dimyv0.min() 3065 dyx = dimyv0.max() 3066 3067 if xaxv[0] == 'pretty': 3068 dimxt0 = np.array(gen.pretty_int(dxn,dxx,xaxv[2])) 3069 elif xaxv[0] == 'Nfix': 3070 dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2])) 3071 elif xaxv[0] == 'Vfix': 3072 dimxt0 = np.arange(0,dxx,xaxv[2]) 3073 if yaxv[0] == 'pretty': 3074 dimyt0 = np.array(gen.pretty_int(dyn,dyx,yaxv[2])) 3075 elif yaxv[0] == 'Nfix': 3076 dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2])) 3077 elif yaxv[0] == 'Vfix': 3078 dimyt0 = np.arange(0,dyx,yaxv[2]) 3079 3080 dimxl0 = [] 3081 for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1])) 3082 dimyl0 = [] 3083 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1])) 3084 3085 dimxT0 = 'x' 3086 dimyT0 = 'y' 3087 3088 if mapv is not None: 3089 pixkind = 'data' 3090 else: 3091 # No following data values 3092 dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0)) 3093 dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0)) 3094 pixkind = 'fixpixel' 3095 3096 # No transformation 3097 # if reva is not None: 3098 # extravals, xval, yval, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT = \ 3099 # transform(extravals, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0, \ 3100 # dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0) 3101 # else: 3102 # dimxv = dimxv0 3103 # dimyv = dimyv0 3104 # dimxt = dimxt0 3105 # dimyt = dimyt0 3106 # dimxl = dimxl0 3107 # dimyl = dimyl0 3108 # dimxT = dimxT0 3109 # dimyT = dimyT0 3110 3111 dimxv = dimxv0 3112 dimyv = dimyv0 3113 dimxt = dimxt0 3114 dimyt = dimyt0 3115 dimxl = dimxl0 3116 dimyl = dimyl0 3117 dimxT = dimxT0 3118 dimyT = dimyT0 3119 3054 3120 # Canging line kinds every 7 pts (end of standard colors) 3055 3121 ptkinds=['.','x','o','*','+','8','>','D','h','p','s'] … … 3128 3194 plt.pcolormesh(x, y, extravals, cmap=plt.get_cmap(extrapar[3]), \ 3129 3195 vmin=extrapar[1], vmax=extrapar[2]) 3130 cbar = plt.colorbar() 3131 cbar.set_label(extrapar[0].replace('_','\_') +'('+ units_lunits(extrapar[4])+\ 3196 if extrapar[5] == 'horizontal': 3197 cbar = plt.colorbar(format=extrapar[4],orientation=extrapar[5]) 3198 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 3199 ticklabels= cbar.ax.get_xticklabels() 3200 Nticks = len(ticklabels) 3201 ticklabs = [] 3202 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 3203 cbar.ax.set_xticklabels(ticklabs,rotation=90) 3204 else: 3205 cbar = plt.colorbar(format=extrapar[4],orientation=extrapar[5]) 3206 3207 cbar.set_label(gen.latex_text(extrapar[0]) +'('+ units_lunits(extrapar[6]) + \ 3132 3208 ')') 3133 3209 … … 3139 3215 3140 3216 if figk[0:8] == 'labelled': 3217 if len(figk.split(',')) != 3: 3218 print errormsg 3219 print ' ' + fname + ": 'labelled' requires two additional values !!" 3220 print " 'labelled',[txtsize],[txtcolor]" 3221 quit(-1) 3141 3222 txtsize=int(figk.split(',')[1]) 3142 3223 txtcol=figk.split(',')[2] … … 3150 3231 plt.plot(xval, yval, '.', color=ptcol) 3151 3232 3152 graphtit = vtit.replace('_','\_').replace('&','\&')3153 3154 plt.title(graphtit .replace('|', ' '))3233 graphtit = gen.latex_text(vtit.replace('|',' ')) 3234 3235 plt.title(graphtit) 3155 3236 3156 output_kind(kfig, figname, True)3237 output_kind(kfig, figname, ifclose) 3157 3238 3158 3239 return
Note: See TracChangeset
for help on using the changeset viewer.