source: trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/myhisto.py @ 1029

Last change on this file since 1029 was 1029, checked in by aslmd, 11 years ago

UTIL PYTHON planetoplot_v2

  • added keywords nxticks nyticks xp yp missing for improved plot settings
  • added function to print contents of pp object
  • added to ppplot a function figureref to easily set a figure of given size
  • bug fix affecting .ppobj objects containing fields with missing values
  • bug fix when size of z coordinate do not match field
  • bug fix for Ls time coordinates (added changetime=correctls)
  • bug fix if not connected to internet
  • tidying up examples
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#! /usr/bin/env python
2from ppclass import pp
3from    netCDF4               import    Dataset
4from    numpy                 import    *
5import  numpy                 as        np
6import  matplotlib.pyplot     as        mpl
7
8## Author: Tanguy Bertrand
9
10## Exemple d'histogramme
11#
12# INPUT :
13#
14# file
15# nb_dataset: number of dataset that is number of superposed histograms
16# Time range
17# altitude range
18# longitude range
19# latitude range
20# step: gap on xaxis between two ticks. Ex: step = 1 leads to one bar for each unit of the selected variable 
21# variable : u, v, w, icetot, tsurf ...
22
23############################
24filename="diagfi1.nc"
25nb_dataset=3
26tint=[["0.25,1.5"],["0.25,5.5"],["0.25,10.5"]] #Time must be as written in the input file
27zint=[["0.1,10"],["0.1,10"],["0.1,10"]] #alt in km
28xarea="-180,180"
29yarea="-90,90"
30step=5 
31var="u" #variable
32############################
33
34x=np.zeros(nb_dataset,dtype='object') #object of all datasets
35
36bornemax=0. # initialisation boundary values
37bornemin=0.
38
39for i in range(nb_dataset):
40
41        myvar = pp(file=filename,var=var,t=tint[i],z=zint[i],x=xarea,y=yarea,compute="nothing").getf()  # get data to be changed according to selected variable
42        data=np.ravel(myvar)
43               
44        x[i]=np.array(data)
45       
46        #upper lower bounds:   
47        maxval=np.amax(myvar)       
48        romax=round(maxval,0)
49        if abs(romax/maxval) < 1: romax=romax+1 
50
51        minval=np.amin(myvar)       
52        romin=round(minval,0)
53        if abs(romin/minval) < 1: romin=romin-1 
54
55        bornemax=np.amax([romax,bornemax])
56        bornemin=np.amin([romin,bornemin])
57        #
58       
59        print 'minval,maxval=',minval,romax
60        print 'romin,romax=',romin,romax
61        print 'bornemin,bornemax=',bornemin,bornemax
62       
63# bins definition:
64bins=np.arange(bornemin,bornemax+1,step)
65
66
67
68vect=[x[0],x[1],x[2]] #vecteur of datasets to be changed according to the number of desired datasets
69
70## PLOT
71# legend:
72zelab=['time: '+str(tint[0])+' - alt: '+str(zint[0])+' km','time: '+str(tint[1])+' - alt: '+str(zint[1])+' km','time: '+str(tint[2])+' - alt: '+str(zint[2])+' km']
73# Histogram : normed, probability
74mpl.hist(vect,bins,normed=1,histtype='bar',align='mid',rwidth=0.8,label=zelab)
75mpl.legend(prop={'size':20})
76mpl.title('U wind distribution',fontsize=20)
77mpl.xlabel('Horizontal Wind (m.s-1)',fontsize=20)
78mpl.ylabel('Probability',fontsize=20)
79mpl.xticks(bins,fontsize=16)
80mpl.yticks(fontsize=16)
81mpl.grid(True)
82
83mpl.show()
84
85
86mpl.figure(5)
87 
Note: See TracBrowser for help on using the repository browser.