@@ -23,9 +23,11 @@ Plot multiple curves given by `Ys` against a common x-axis `X`.
2323- `disp`: A boolean indicating whether to display the plot. If false, only create a structure to be displayed later.
2424 Default is `false`.
2525"""
26- function plot(X, Ys:: AbstractVector{<:Union{AbstractVector, Tuple}} ; xlabel= " " , ylabel= " " ,
27- labels= nothing , xlims= nothing , ylims= nothing , ann= nothing , scatter= false ,
28- title= " " , fig= " " , ysize= 14 , disp= false )
26+ function plot(
27+ X, Ys:: AbstractVector{<:Union{AbstractVector, Tuple}} ; xlabel = " " , ylabel = " " ,
28+ labels = nothing , xlims = nothing , ylims = nothing , ann = nothing , scatter = false ,
29+ title = " " , fig = " " , ysize = 14 , disp = false
30+ )
2931 if disp
3032 if fig != " "
3133 plt. figure(fig)
@@ -43,56 +45,58 @@ function plot(X, Ys::AbstractVector{<:Union{AbstractVector, Tuple}}; xlabel="",
4345 if YT isa Tuple
4446 Y, Yerr = YT
4547 if isnothing(labels)
46- plt. errorbar(X, Y, yerr= Yerr, capsize= 5 )
48+ plt. errorbar(X, Y, yerr = Yerr, capsize = 5 )
4749 else
48- if isnothing(labels[i]) || labels[i]== " "
49- plt. errorbar(X, Y, yerr= Yerr, capsize= 5 )
50+ if isnothing(labels[i]) || labels[i] == " "
51+ plt. errorbar(X, Y, yerr = Yerr, capsize = 5 )
5052 else
51- plt. errorbar(X, Y, yerr= Yerr; label= labels[i], capsize= 5 )
53+ plt. errorbar(X, Y, yerr = Yerr; label = labels[i], capsize = 5 )
5254 end
5355 end
5456 if scatter
55- plt. scatter(X, Y; s= 24 , c= " red" , alpha= 1 )
57+ plt. scatter(X, Y; s = 24 , c = " red" , alpha = 1 )
5658 end
5759 else
5860 Y = YT
5961 if isnothing(labels)
6062 plt. plot(X, Y)
6163 else
62- if isnothing(labels[i]) || labels[i]== " "
64+ if isnothing(labels[i]) || labels[i] == " "
6365 plt. plot(X, Y)
6466 else
65- plt. plot(X, Y; label= labels[i])
67+ plt. plot(X, Y; label = labels[i])
6668 end
6769 end
6870 if scatter
69- plt. scatter(X, Y; s= 24 , c= " red" , alpha= 1 )
71+ plt. scatter(X, Y; s = 24 , c = " red" , alpha = 1 )
7072 end
7173 end
7274 end
7375 if xlabel != " "
74- plt. xlabel(xlabel, fontsize= 14 );
76+ plt. xlabel(xlabel, fontsize = 14 )
7577 end
7678 if ylabel != " "
77- plt. ylabel(ylabel, fontsize= ysize);
79+ plt. ylabel(ylabel, fontsize = ysize)
7880 end
7981 if ! isnothing(xlims)
8082 plt. xlim(xlims)
8183 end
8284 plt. grid(true )
83- plt. grid(which= " major" , color= " #DDDDDD" )
85+ plt. grid(which = " major" , color = " #DDDDDD" )
8486 plt. legend()
8587 plt. tight_layout()
8688 end
87- PlotX(X, Ys, labels, xlabel, ylabel, ysize, nothing , nothing , nothing , xlims, ylims, ann, scatter, title, fig, nothing , 4 )
89+ return PlotX(X, Ys, labels, xlabel, ylabel, ysize, nothing , nothing , nothing , xlims, ylims, ann, scatter, title, fig, nothing , 4 )
8890end
8991
90- function plot(X, Y1:: AbstractVector{<:AbstractVector} , Y2:: AbstractVector{<:Number} ;
91- xlabel= " " , ylabels= [" " , " " ], labels= [" " , " " ],
92- xlims= nothing , ylims= nothing , ann= nothing , scatter= false ,
93- title= " " , fig= " " , ysize= 14 , disp= false )
94- if length(Y1) == 1
95- plot(X, Y1[1 ], Y2; xlabel= xlabel, ylabels, labels, xlims, ylims, ann, scatter, title, fig, ysize, disp)
92+ function plot(
93+ X, Y1:: AbstractVector{<:AbstractVector} , Y2:: AbstractVector{<:Number} ;
94+ xlabel = " " , ylabels = [" " , " " ], labels = [" " , " " ],
95+ xlims = nothing , ylims = nothing , ann = nothing , scatter = false ,
96+ title = " " , fig = " " , ysize = 14 , disp = false
97+ )
98+ return if length(Y1) == 1
99+ plot(X, Y1[1 ], Y2; xlabel = xlabel, ylabels, labels, xlims, ylims, ann, scatter, title, fig, ysize, disp)
96100 else
97101 if disp
98102 if fig != " "
@@ -101,36 +105,41 @@ function plot(X, Y1::AbstractVector{<:AbstractVector}, Y2::AbstractVector{<:Numb
101105 if title != " "
102106 plt. title(title)
103107 end
104- colors= [" green" , " grey" , " red" ]
108+ colors = [" green" , " grey" , " red" ]
105109 lns = []
106110 for (i, Y) in pairs(Y1)
107- ln, = plt. plot(X, Y; label= labels[i], color= colors[i])
111+ ln, = plt. plot(X, Y; label = labels[i], color = colors[i])
108112 push!(lns, ln)
109- if i== 1 && xlabel != " "
110- plt. xlabel(xlabel, fontsize= 14 );
113+ if i == 1 && xlabel != " "
114+ plt. xlabel(xlabel, fontsize = 14 )
111115 if ylabels != [" " , " " ]
112- plt. ylabel(ylabels[1 ], fontsize= ysize);
116+ plt. ylabel(ylabels[1 ], fontsize = ysize)
113117 end
114118 end
115119 end
116120 plt. twinx()
117- ln, = plt. plot(X, Y2; label= labels[3 ], color= colors[end ])
121+ ln, = plt. plot(X, Y2; label = labels[3 ], color = colors[end ])
118122 push!(lns, ln)
119- plt. ylabel(ylabels[2 ], fontsize= ysize);
123+ plt. ylabel(ylabels[2 ], fontsize = ysize)
120124 plt. grid(true )
121- plt. grid(which= " major" , color= " #DDDDDD" )
122- plt. legend(lns, labels, loc= " best" )
125+ plt. grid(which = " major" , color = " #DDDDDD" )
126+ plt. legend(lns, labels, loc = " best" )
123127 plt. tight_layout()
124128 end
125- PlotX(X, [Y1, Y2], labels, xlabel, ylabels, ysize, nothing , nothing , nothing , xlims, ylims, ann, scatter, title, fig, nothing , 5 )
129+ PlotX(
130+ X, [Y1, Y2], labels, xlabel, ylabels, ysize, nothing , nothing , nothing ,
131+ xlims, ylims, ann, scatter, title, fig, nothing , 5
132+ )
126133 end
127-
134+
128135end
129136
130- function plot(X, Y1:: AbstractVector{<:Number} , Y2:: AbstractVector{<:Number} ;
131- xlabel= " " , ylabels= [" " , " " ], labels= [" " , " " ],
132- xlims= nothing , ylims= nothing , ann= nothing , scatter= false ,
133- title= " " , fig= " " , ysize= 14 , disp= false )
137+ function plot(
138+ X, Y1:: AbstractVector{<:Number} , Y2:: AbstractVector{<:Number} ;
139+ xlabel = " " , ylabels = [" " , " " ], labels = [" " , " " ],
140+ xlims = nothing , ylims = nothing , ann = nothing , scatter = false ,
141+ title = " " , fig = " " , ysize = 14 , disp = false
142+ )
134143 local l1, l2
135144 if disp
136145 if fig != " "
@@ -143,65 +152,70 @@ function plot(X, Y1::AbstractVector{<:Number}, Y2::AbstractVector{<:Number};
143152 labels = ylabels
144153 end
145154 for (i, Y) in pairs([Y1, Y2])
146-
147- if i== 1
148- l1, = plt. plot(X, Y; label= labels[i], color= " green" )
155+
156+ if i == 1
157+ l1, = plt. plot(X, Y; label = labels[i], color = " green" )
149158 if xlabel != " "
150- plt. xlabel(xlabel, fontsize= 14 );
159+ plt. xlabel(xlabel, fontsize = 14 )
151160 end
152161 if ylabels != [" " , " " ]
153- plt. ylabel(ylabels[1 ], fontsize= ysize);
162+ plt. ylabel(ylabels[1 ], fontsize = ysize)
154163 end
155164 if ! isnothing(ylims)
156165 plt. ylim(ylims[1 ])
157166 end
158167 if scatter
159- plt. scatter(X, Y; s= 24 , c= " red" , alpha= 1 )
168+ plt. scatter(X, Y; s = 24 , c = " red" , alpha = 1 )
160169 end
161170 plt. twinx()
162171 else
163- l2, = plt. plot(X, Y; label= labels[i], color= " red" )
172+ l2, = plt. plot(X, Y; label = labels[i], color = " red" )
164173 if ylabels[2 ] != " "
165- plt. ylabel(ylabels[2 ], fontsize= ysize);
174+ plt. ylabel(ylabels[2 ], fontsize = ysize)
166175 end
167176 if ! isnothing(ylims)
168177 plt. ylim(ylims[2 ])
169178 end
170179 if scatter
171- plt. scatter(X, Y; s= 24 , c= " red" , alpha= 1 )
180+ plt. scatter(X, Y; s = 24 , c = " red" , alpha = 1 )
172181 end
173182 end
174183 end
175184
176185 plt. grid(true )
177- plt. grid(which= " major" , color= " #DDDDDD" )
186+ plt. grid(which = " major" , color = " #DDDDDD" )
178187
179188 lns = [l1, l2]
180- plt. legend(lns, labels, loc= " best" )
189+ plt. legend(lns, labels, loc = " best" )
181190 plt. tight_layout()
182191 end
183- PlotX(X, [Y1, Y2], labels, xlabel, ylabels, ysize, nothing , nothing , nothing , xlims, ylims, ann, scatter, title, fig, nothing , 5 )
192+ return PlotX(
193+ X, [Y1, Y2], labels, xlabel, ylabels, ysize, nothing , nothing , nothing ,
194+ xlims, ylims, ann, scatter, title, fig, nothing , 5
195+ )
184196end
185197
186- function plot(Y:: AbstractVector{<:Number} ; xlabel= " " , ylabel= " " , title= " " , fig= " " , ysize= 14 , disp= false )
198+ function plot(Y:: AbstractVector{<:Number} ; xlabel = " " , ylabel = " " , title = " " , fig = " " , ysize = 14 , disp = false )
187199 X = collect(eachindex(Y))
188- plot(X, Y; xlabel, ylabel, title, fig, disp, ysize)
200+ return plot(X, Y; xlabel, ylabel, title, fig, disp, ysize)
189201end
190202
191- function plot(X, Y:: AbstractVector{<:Number} ; xlabel= " " , ylabel= " " , xlims= nothing , ylims= nothing , ann= nothing ,
192- scatter= false , title= " " , fig= " " , ysize= 14 , disp= false )
203+ function plot(
204+ X, Y:: AbstractVector{<:Number} ; xlabel = " " , ylabel = " " , xlims = nothing , ylims = nothing , ann = nothing ,
205+ scatter = false , title = " " , fig = " " , ysize = 14 , disp = false
206+ )
193207 if disp
194208 if fig != " "
195209 plt. figure(fig)
196210 end
197211 if title != " "
198212 plt. title(title)
199213 end
200- plt. plot(X, Y; label= ylabel)
214+ plt. plot(X, Y; label = ylabel)
201215 if xlabel != " "
202- plt. xlabel(xlabel, fontsize= 14 );
216+ plt. xlabel(xlabel, fontsize = 14 )
203217 end
204- plt. ylabel(ylabel; fontsize= ysize);
218+ plt. ylabel(ylabel; fontsize = ysize)
205219 if isnothing(xlims)
206220 plt. xlim(X[begin ], X[end ])
207221 else
@@ -211,15 +225,17 @@ function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", xlims=nothin
211225 plt. ylim(ylims)
212226 end
213227 if ! isnothing(ann)
214- plt. annotate(ann[3 ], xy = (ann[1 ], ann[2 ]), fontsize = 14 )
228+ plt. annotate(ann[3 ], xy = (ann[1 ], ann[2 ]), fontsize = 14 )
215229 end
216230 if scatter
217- plt. scatter(X, Y; s= 24 , c= " red" , alpha= 1 )
231+ plt. scatter(X, Y; s = 24 , c = " red" , alpha = 1 )
218232 end
219233 plt. grid(true )
220- plt. grid(which= " major" , color= " #DDDDDD" )
234+ plt. grid(which = " major" , color = " #DDDDDD" )
221235 plt. tight_layout()
222236 end
223- PlotX(X, Y, nothing , xlabel, ylabel, ysize, nothing , nothing , nothing , xlims, ylims, ann, scatter, title, fig, nothing , 1 )
237+ return PlotX(
238+ X, Y, nothing , xlabel, ylabel, ysize, nothing , nothing , nothing ,
239+ xlims, ylims, ann, scatter, title, fig, nothing , 1
240+ )
224241end
225-
0 commit comments