|
1 |
| -!***************************************************************************************** |
2 |
| -!> author: Jacob Williams |
3 |
| -! date: 4/14/2015 |
4 |
| -! license: BSD |
5 |
| -! |
6 |
| -! Unit test for [[pyplot_module]]. |
7 |
| - |
8 |
| - program test |
9 |
| - |
10 |
| - use pyplot_module, only : pyplot, wp => pyplot_wp |
11 |
| - |
12 |
| - implicit none |
13 |
| - |
14 |
| - integer,parameter :: n = 100 |
15 |
| - |
16 |
| - real(wp), dimension(:),allocatable :: x !! x values |
17 |
| - real(wp), dimension(:),allocatable :: y !! y values |
18 |
| - real(wp), dimension(:),allocatable :: xerr !! error values |
19 |
| - real(wp), dimension(:),allocatable :: yerr !! error values for bar chart |
20 |
| - real(wp), dimension(:),allocatable :: sx !! sin(x) values |
21 |
| - real(wp), dimension(:),allocatable :: cx !! cos(x) values |
22 |
| - real(wp), dimension(:),allocatable :: zx !! |
23 |
| - real(wp), dimension(:),allocatable :: tx !! sin(x)*cos(x) values |
24 |
| - real(wp), dimension(:,:),allocatable :: z !! z matrix for contour plot |
25 |
| - real(wp), dimension(:,:),allocatable :: mat !! image values |
26 |
| - type(pyplot) :: plt !! pytplot handler |
27 |
| - integer :: i !! counter |
28 |
| - integer :: j !! counter |
29 |
| - real(wp) :: r2 !! temp variable |
30 |
| - integer :: istat !! status code |
31 |
| - |
32 |
| - real(wp),parameter :: pi = acos(-1.0_wp) |
33 |
| - real(wp),parameter :: deg2rad = pi/180.0_wp |
34 |
| - |
35 |
| - character(len=*), parameter :: testdir = "test/" |
36 |
| - |
37 |
| - ! size arrays: |
38 |
| - allocate(x(n)) |
39 |
| - allocate(y(n)) |
40 |
| - allocate(yerr(n)) |
41 |
| - allocate(sx(n)) |
42 |
| - allocate(cx(n)) |
43 |
| - allocate(zx(n)) |
44 |
| - allocate(tx(n)) |
45 |
| - allocate(z(n,n)) |
46 |
| - allocate(mat(n,n)) |
47 |
| - |
48 |
| - !generate some data: |
49 |
| - x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp |
50 |
| - sx = sin(x) |
51 |
| - cx = cos(x) |
52 |
| - tx = sx * cx |
53 |
| - zx = 0.0_wp |
54 |
| - yerr = abs(sx*.25_wp) |
55 |
| - |
56 |
| - do i=1,n |
57 |
| - do j=1,n |
58 |
| - mat(i,j) = sin(real(i,wp)*real(j,wp)) |
59 |
| - end do |
60 |
| - end do |
61 |
| - |
62 |
| - !2d line plot: |
63 |
| - call plt%initialize(grid=.true.,xlabel='angle (rad)',figsize=[20,10],& |
64 |
| - title='plot test',legend=.true.,axis_equal=.true.,& |
65 |
| - tight_layout=.true.) |
66 |
| - call plt%add_plot(x,sx,label='$\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat) |
67 |
| - call plt%add_plot(x,cx,label='$\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat) |
68 |
| - call plt%add_plot(x,tx,label='$\sin (x) \cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat) |
69 |
| - call plt%savefig(testdir//'plottest.png', pyfile=testdir//'plottest.py',& |
70 |
| - istat=istat) |
71 |
| - |
72 |
| - !bar chart: |
73 |
| - tx = 0.1_wp !for bar width |
74 |
| - call plt%initialize(grid=.true.,xlabel='angle (rad)',& |
75 |
| - title='bar test',legend=.true.,figsize=[20,10],& |
76 |
| - font_size = 20,& |
77 |
| - axes_labelsize = 20,& |
78 |
| - xtick_labelsize = 20,& |
79 |
| - ytick_labelsize = 20,& |
80 |
| - legend_fontsize = 20, raw_strings=.true. ) |
81 |
| - call plt%add_bar(x=x,height=sx,width=tx,label='$\sin (x)$',& |
82 |
| - color='r',yerr=yerr,xlim=[0.0_wp, 20.0_wp],align='center',istat=istat) |
83 |
| - call plt%savefig(testdir//'bartest.png', pyfile=testdir//'bartest.py',& |
84 |
| - istat=istat) |
85 |
| - |
86 |
| - !contour plot: |
87 |
| - x = [(real(i,wp), i=0,n-1)]/100.0_wp |
88 |
| - y = [(real(i,wp), i=0,n-1)]/100.0_wp |
89 |
| - do i=1,n |
90 |
| - do j=1,n |
91 |
| - r2 = x(i)**2 + y(j)**2 |
92 |
| - z(i,j) = sin(x(i))*cos(y(j))*sin(r2)/(1.0_wp+log(r2+1.0_wp)) |
93 |
| - end do |
94 |
| - end do |
95 |
| - call plt%initialize(grid=.true.,xlabel='x angle (rad)',& |
96 |
| - ylabel='y angle (rad)',figsize=[10,10],& |
97 |
| - title='Contour plot test', real_fmt='*',& |
98 |
| - axisbelow=.false.) |
99 |
| - call plt%add_contour(x, y, z, linestyle='-', & |
100 |
| - filled=.true., cmap='bone', colorbar=.true.,& |
101 |
| - istat=istat) |
102 |
| - call plt%savefig(testdir//'contour.png',pyfile=testdir//'contour.py',istat=istat) |
103 |
| - |
104 |
| - !image plot: |
105 |
| - call plt%initialize(grid=.true.,xlabel='x',ylabel='y',figsize=[20,20],& |
106 |
| - title='imshow test',& |
107 |
| - real_fmt='(F9.3)') |
108 |
| - call plt%add_imshow(mat,xlim=[0.0_wp, 100.0_wp],ylim=[0.0_wp, 100.0_wp],istat=istat) |
109 |
| - call plt%savefig(testdir//'imshow.png', pyfile=testdir//'imshow.py',& |
110 |
| - istat=istat) |
111 |
| - |
112 |
| - !wireframe plot: |
113 |
| - call plt%initialize(grid=.true.,xlabel='x angle (rad)',& |
114 |
| - ylabel='y angle (rad)',figsize=[10,10],& |
115 |
| - title='Wireframe plot test', real_fmt='*',& |
116 |
| - axisbelow=.false.,mplot3d=.true.,use_numpy=.true.) |
117 |
| - call plt%plot_wireframe(x, y, z, label='', linestyle='-', & |
118 |
| - cmap='bone', colorbar=.true.,& |
119 |
| - istat=istat) |
120 |
| - call plt%savefig(testdir//'wireframe.png', pyfile=testdir//'wireframe.py',& |
121 |
| - istat=istat) |
122 |
| - |
123 |
| - !histogram chart: |
124 |
| - x = [0.194,0.501,-1.241,1.425,-2.217,-0.342,-0.979,0.909,0.994,0.101, & |
125 |
| - -0.131,-0.627,0.463,1.404,0.036,-2.000,0.109,1.250,-1.035,-1.115, & |
126 |
| - 0.935,0.496,1.100,0.770,-1.307,-0.693,-0.072,-1.331,-0.701, & |
127 |
| - -0.494,0.666,-0.313,-0.430,-0.654,1.638,-0.334,-0.418,0.550,-0.034, & |
128 |
| - 0.473,0.704,0.801,-0.157,0.055,-0.057,-1.049,-1.022,0.495,0.756, & |
129 |
| - 0.149,0.543,-0.813,-0.171,-0.994,-1.532,0.502,1.324,-0.593,-0.467, & |
130 |
| - 0.372,-0.904,1.255,0.931,-0.779,1.529,-0.036,0.783,0.292,-0.792, & |
131 |
| - -0.223,-0.325,0.225,-0.492,-0.941,0.065,1.300,-1.241,-1.124,-0.499, & |
132 |
| - 1.233,-0.845,-0.948,-1.060,1.103,-1.154,-0.594,0.335,-1.423,0.571, & |
133 |
| - -0.903,1.129,-0.372,-1.043,-1.327,0.147,1.056,1.068,-0.699,0.988,-0.630] |
134 |
| - |
135 |
| - call plt%initialize(grid=.true.,xlabel='x',& |
136 |
| - title='hist test',& |
137 |
| - legend=.true.,figsize=[20,10],& |
138 |
| - font_size = 20,& |
139 |
| - axes_labelsize = 20,& |
140 |
| - xtick_labelsize = 20,& |
141 |
| - ytick_labelsize = 20,& |
142 |
| - legend_fontsize = 20 ) |
143 |
| - |
144 |
| - call plt%add_hist(x=x, label='x',istat=istat) |
145 |
| - call plt%savefig(testdir//'histtest1.png', pyfile=testdir//'histtest1.py',& |
146 |
| - istat=istat) |
147 |
| - |
148 |
| - call plt%initialize(grid=.true.,xlabel='x',& |
149 |
| - title='cumulative hist test',& |
150 |
| - legend=.true.,figsize=[20,10],& |
151 |
| - font_size = 20,& |
152 |
| - axes_labelsize = 20,& |
153 |
| - xtick_labelsize = 20,& |
154 |
| - ytick_labelsize = 20,& |
155 |
| - legend_fontsize = 20 ) |
156 |
| - |
157 |
| - call plt%add_hist(x=x, label='x', bins=8, cumulative=.true.,istat=istat) |
158 |
| - call plt%savefig(testdir//'histtest2.png', & |
159 |
| - pyfile=testdir//'histtest2.py', & |
160 |
| - dpi='200', & |
161 |
| - transparent=.true.,istat=istat) |
162 |
| - |
163 |
| - !3D plot: |
164 |
| - call plt%initialize(grid=.true.,& |
165 |
| - xlabel='x (km)',ylabel='y (km)',zlabel='z (km)',& |
166 |
| - title='Orbit',& |
167 |
| - axis_equal=.true.,& |
168 |
| - mplot3d=.true.,& |
169 |
| - figsize=[20,10] ) |
170 |
| - |
171 |
| - x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp |
172 |
| - sx = 7000.0_wp * cos(x * deg2rad) |
173 |
| - cx = 7000.0_wp * sin(x * deg2rad) |
174 |
| - zx = 0.0_wp |
175 |
| - call plt%add_3d_plot(sx,cx,zx,& |
176 |
| - label='orbit',linestyle='r-',& |
177 |
| - linewidth=2,istat=istat) |
178 |
| - call plt%add_sphere(6378.0_wp,0.0_wp,0.0_wp,0.0_wp,& |
179 |
| - color='Blue',n_facets=500,& |
180 |
| - antialiased=.true.,istat=istat) |
181 |
| - call plt%savefig(testdir//'orbit.png', & |
182 |
| - pyfile=testdir//'orbit.py', & |
183 |
| - dpi='200', & |
184 |
| - transparent=.true.,istat=istat) |
185 |
| - |
186 |
| - ! Errorbar plot: |
187 |
| - call plt%initialize(grid=.true.,& |
188 |
| - xlabel='x',ylabel='y',& |
189 |
| - title='Errorbar Plot Example',& |
190 |
| - figsize=[20,10] ) |
191 |
| - |
192 |
| - x = [(real(i,wp), i=0, 360, 10)] |
193 |
| - y = 10.0_wp * cos(x * deg2rad) |
194 |
| - xerr = sin(x * deg2rad) * 5.0_wp |
195 |
| - yerr = sin(y * deg2rad) * 10.0_wp |
196 |
| - |
197 |
| - call plt%add_errorbar(x, y, label='y', linestyle='.', & |
198 |
| - xerr=xerr, yerr=yerr, istat=istat) |
199 |
| - call plt%savefig(testdir//'errorbar.png', & |
200 |
| - pyfile=testdir//'errorbar.py', & |
201 |
| - dpi='200', & |
202 |
| - transparent=.true.,istat=istat, python='python') |
203 |
| - |
204 |
| - end program test |
205 |
| -!***************************************************************************************** |
| 1 | +!***************************************************************************************** |
| 2 | +!> author: Jacob Williams |
| 3 | +! date: 4/14/2015 |
| 4 | +! license: BSD |
| 5 | +! |
| 6 | +! Unit test for [[pyplot_module]]. |
| 7 | + |
| 8 | + program test |
| 9 | + |
| 10 | + use pyplot_module, only : pyplot, wp => pyplot_wp |
| 11 | + |
| 12 | + implicit none |
| 13 | + |
| 14 | + integer,parameter :: n = 100 |
| 15 | + |
| 16 | + real(wp), dimension(:),allocatable :: x !! x values |
| 17 | + real(wp), dimension(:),allocatable :: y !! y values |
| 18 | + real(wp), dimension(:),allocatable :: xerr !! error values |
| 19 | + real(wp), dimension(:),allocatable :: yerr !! error values for bar chart |
| 20 | + real(wp), dimension(:),allocatable :: sx !! sin(x) values |
| 21 | + real(wp), dimension(:),allocatable :: cx !! cos(x) values |
| 22 | + real(wp), dimension(:),allocatable :: zx !! |
| 23 | + real(wp), dimension(:),allocatable :: tx !! sin(x)*cos(x) values |
| 24 | + real(wp), dimension(:,:),allocatable :: z !! z matrix for contour plot |
| 25 | + real(wp), dimension(:,:),allocatable :: mat !! image values |
| 26 | + type(pyplot) :: plt !! pytplot handler |
| 27 | + integer :: i !! counter |
| 28 | + integer :: j !! counter |
| 29 | + real(wp) :: r2 !! temp variable |
| 30 | + integer :: istat !! status code |
| 31 | + |
| 32 | + real(wp),parameter :: pi = acos(-1.0_wp) |
| 33 | + real(wp),parameter :: deg2rad = pi/180.0_wp |
| 34 | + |
| 35 | + character(len=*), parameter :: testdir = "test/" |
| 36 | + |
| 37 | + ! size arrays: |
| 38 | + allocate(x(n)) |
| 39 | + allocate(y(n)) |
| 40 | + allocate(yerr(n)) |
| 41 | + allocate(sx(n)) |
| 42 | + allocate(cx(n)) |
| 43 | + allocate(zx(n)) |
| 44 | + allocate(tx(n)) |
| 45 | + allocate(z(n,n)) |
| 46 | + allocate(mat(n,n)) |
| 47 | + |
| 48 | + !generate some data: |
| 49 | + x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp |
| 50 | + sx = sin(x) |
| 51 | + cx = cos(x) |
| 52 | + tx = sx * cx |
| 53 | + zx = 0.0_wp |
| 54 | + yerr = abs(sx*.25_wp) |
| 55 | + |
| 56 | + do i=1,n |
| 57 | + do j=1,n |
| 58 | + mat(i,j) = sin(real(i,wp)*real(j,wp)) |
| 59 | + end do |
| 60 | + end do |
| 61 | + |
| 62 | + !2d line plot: |
| 63 | + call plt%initialize(grid=.true.,xlabel='angle (rad)',figsize=[20,10],& |
| 64 | + title='plot test',legend=.true.,axis_equal=.true.,& |
| 65 | + tight_layout=.true.) |
| 66 | + call plt%add_plot(x,sx,label='$\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat) |
| 67 | + call plt%add_plot(x,cx,label='$\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat) |
| 68 | + call plt%add_plot(x,tx,label='$\sin (x) \cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat) |
| 69 | + call plt%savefig(testdir//'plottest.png', pyfile=testdir//'plottest.py',& |
| 70 | + istat=istat) |
| 71 | + |
| 72 | + !bar chart: |
| 73 | + tx = 0.1_wp !for bar width |
| 74 | + call plt%initialize(grid=.true.,xlabel='angle (rad)',& |
| 75 | + title='bar test',legend=.true.,figsize=[20,10],& |
| 76 | + font_size = 20,& |
| 77 | + axes_labelsize = 20,& |
| 78 | + xtick_labelsize = 20,& |
| 79 | + ytick_labelsize = 20,& |
| 80 | + legend_fontsize = 20, raw_strings=.true. ) |
| 81 | + call plt%add_bar(x=x,height=sx,width=tx,label='$\sin (x)$',& |
| 82 | + color='r',yerr=yerr,xlim=[0.0_wp, 20.0_wp],align='center',istat=istat) |
| 83 | + call plt%savefig(testdir//'bartest.png', pyfile=testdir//'bartest.py',& |
| 84 | + istat=istat) |
| 85 | + |
| 86 | + !contour plot: |
| 87 | + x = [(real(i,wp), i=0,n-1)]/100.0_wp |
| 88 | + y = [(real(i,wp), i=0,n-1)]/100.0_wp |
| 89 | + do i=1,n |
| 90 | + do j=1,n |
| 91 | + r2 = x(i)**2 + y(j)**2 |
| 92 | + z(i,j) = sin(x(i))*cos(y(j))*sin(r2)/(1.0_wp+log(r2+1.0_wp)) |
| 93 | + end do |
| 94 | + end do |
| 95 | + call plt%initialize(grid=.true.,xlabel='x angle (rad)',& |
| 96 | + ylabel='y angle (rad)',figsize=[10,10],& |
| 97 | + title='Contour plot test', real_fmt='*',& |
| 98 | + axisbelow=.false.) |
| 99 | + call plt%add_contour(x, y, z, linestyle='-', & |
| 100 | + filled=.true., cmap='bone', colorbar=.true.,& |
| 101 | + istat=istat) |
| 102 | + call plt%savefig(testdir//'contour.png',pyfile=testdir//'contour.py',istat=istat) |
| 103 | + |
| 104 | + !image plot: |
| 105 | + call plt%initialize(grid=.true.,xlabel='x',ylabel='y',figsize=[20,20],& |
| 106 | + title='imshow test',& |
| 107 | + real_fmt='(F9.3)') |
| 108 | + call plt%add_imshow(mat,xlim=[0.0_wp, 100.0_wp],ylim=[0.0_wp, 100.0_wp],istat=istat) |
| 109 | + call plt%savefig(testdir//'imshow.png', pyfile=testdir//'imshow.py',& |
| 110 | + istat=istat) |
| 111 | + |
| 112 | + !wireframe plot: |
| 113 | + call plt%initialize(grid=.true.,xlabel='x angle (rad)',& |
| 114 | + ylabel='y angle (rad)',figsize=[10,10],& |
| 115 | + title='Wireframe plot test', real_fmt='*',& |
| 116 | + axisbelow=.false.,mplot3d=.true.,use_numpy=.true.) |
| 117 | + call plt%plot_wireframe(x, y, z, label='', linestyle='-', & |
| 118 | + cmap='bone', colorbar=.true.,& |
| 119 | + istat=istat) |
| 120 | + call plt%savefig(testdir//'wireframe.png', pyfile=testdir//'wireframe.py',& |
| 121 | + istat=istat) |
| 122 | + |
| 123 | + !histogram chart: |
| 124 | + x = [0.194,0.501,-1.241,1.425,-2.217,-0.342,-0.979,0.909,0.994,0.101, & |
| 125 | + -0.131,-0.627,0.463,1.404,0.036,-2.000,0.109,1.250,-1.035,-1.115, & |
| 126 | + 0.935,0.496,1.100,0.770,-1.307,-0.693,-0.072,-1.331,-0.701, & |
| 127 | + -0.494,0.666,-0.313,-0.430,-0.654,1.638,-0.334,-0.418,0.550,-0.034, & |
| 128 | + 0.473,0.704,0.801,-0.157,0.055,-0.057,-1.049,-1.022,0.495,0.756, & |
| 129 | + 0.149,0.543,-0.813,-0.171,-0.994,-1.532,0.502,1.324,-0.593,-0.467, & |
| 130 | + 0.372,-0.904,1.255,0.931,-0.779,1.529,-0.036,0.783,0.292,-0.792, & |
| 131 | + -0.223,-0.325,0.225,-0.492,-0.941,0.065,1.300,-1.241,-1.124,-0.499, & |
| 132 | + 1.233,-0.845,-0.948,-1.060,1.103,-1.154,-0.594,0.335,-1.423,0.571, & |
| 133 | + -0.903,1.129,-0.372,-1.043,-1.327,0.147,1.056,1.068,-0.699,0.988,-0.630] |
| 134 | + |
| 135 | + call plt%initialize(grid=.true.,xlabel='x',& |
| 136 | + title='hist test',& |
| 137 | + legend=.true.,figsize=[20,10],& |
| 138 | + font_size = 20,& |
| 139 | + axes_labelsize = 20,& |
| 140 | + xtick_labelsize = 20,& |
| 141 | + ytick_labelsize = 20,& |
| 142 | + legend_fontsize = 20 ) |
| 143 | + |
| 144 | + call plt%add_hist(x=x, label='x',istat=istat) |
| 145 | + call plt%savefig(testdir//'histtest1.png', pyfile=testdir//'histtest1.py',& |
| 146 | + istat=istat) |
| 147 | + |
| 148 | + call plt%initialize(grid=.true.,xlabel='x',& |
| 149 | + title='cumulative hist test',& |
| 150 | + legend=.true.,figsize=[20,10],& |
| 151 | + font_size = 20,& |
| 152 | + axes_labelsize = 20,& |
| 153 | + xtick_labelsize = 20,& |
| 154 | + ytick_labelsize = 20,& |
| 155 | + legend_fontsize = 20 ) |
| 156 | + |
| 157 | + call plt%add_hist(x=x, label='x', bins=8, cumulative=.true.,istat=istat) |
| 158 | + call plt%savefig(testdir//'histtest2.png', & |
| 159 | + pyfile=testdir//'histtest2.py', & |
| 160 | + dpi='200', & |
| 161 | + transparent=.true.,istat=istat) |
| 162 | + |
| 163 | + !3D plot: |
| 164 | + call plt%initialize(grid=.true.,& |
| 165 | + xlabel='x (km)',ylabel='y (km)',zlabel='z (km)',& |
| 166 | + title='Orbit',& |
| 167 | + axis_equal=.true.,& |
| 168 | + mplot3d=.true.,& |
| 169 | + figsize=[20,10] ) |
| 170 | + |
| 171 | + x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp |
| 172 | + sx = 7000.0_wp * cos(x * deg2rad) |
| 173 | + cx = 7000.0_wp * sin(x * deg2rad) |
| 174 | + zx = 0.0_wp |
| 175 | + call plt%add_3d_plot(sx,cx,zx,& |
| 176 | + label='orbit',linestyle='r-',& |
| 177 | + linewidth=2,istat=istat) |
| 178 | + call plt%add_sphere(6378.0_wp,0.0_wp,0.0_wp,0.0_wp,& |
| 179 | + color='Blue',n_facets=500,& |
| 180 | + antialiased=.true.,istat=istat) |
| 181 | + call plt%savefig(testdir//'orbit.png', & |
| 182 | + pyfile=testdir//'orbit.py', & |
| 183 | + dpi='200', & |
| 184 | + transparent=.true.,istat=istat) |
| 185 | + |
| 186 | + ! Errorbar plot: |
| 187 | + call plt%initialize(grid=.true.,& |
| 188 | + xlabel='x',ylabel='y',& |
| 189 | + title='Errorbar Plot Example',& |
| 190 | + figsize=[20,10] ) |
| 191 | + |
| 192 | + x = [(real(i,wp), i=0, 360, 10)] |
| 193 | + y = 10.0_wp * cos(x * deg2rad) |
| 194 | + xerr = abs(sin(x * deg2rad) * 5.0_wp) |
| 195 | + yerr = abs(sin(y * deg2rad) * 10.0_wp) |
| 196 | + |
| 197 | + call plt%add_errorbar(x, y, label='y', linestyle='.', & |
| 198 | + xerr=xerr, yerr=yerr, istat=istat) |
| 199 | + call plt%savefig(testdir//'errorbar.png', & |
| 200 | + pyfile=testdir//'errorbar.py', & |
| 201 | + dpi='200', & |
| 202 | + transparent=.true.,istat=istat, python='python') |
| 203 | + |
| 204 | + end program test |
| 205 | +!***************************************************************************************** |
0 commit comments