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