@@ -71,21 +71,23 @@ DEFAULT_PLOT_FUNC(x,y,z) = (x,y,z) # For v0.5.2 bug
71
71
72
72
syms = getsyms (sol)
73
73
int_vars = interpret_vars (vars,sol,syms)
74
+ strs = cleansyms (syms)
75
+
74
76
tscale = get (plotattributes, :xscale , :identity )
75
77
plot_vecs,labels = diffeq_to_arrays (sol,plot_analytic,denseplot,
76
78
plotdensity,tspan,axis_safety,
77
- vars,int_vars,tscale,syms )
79
+ vars,int_vars,tscale,strs )
78
80
79
81
tdir = sign (sol. t[end ]- sol. t[1 ])
80
82
xflip --> tdir < 0
81
83
seriestype --> :path
82
84
83
85
# Special case labels when vars = (:x,:y,:z) or (:x) or [:x,:y] ...
84
- if typeof (vars) <: Tuple && (typeof (vars[1 ]) == Symbol && typeof (vars[2 ]) == Symbol)
85
- xguide --> vars[ 1 ]
86
- yguide --> vars[ 2 ]
86
+ if typeof (vars) <: Tuple && (issymbollike (vars[1 ]) && issymbollike (vars[2 ]))
87
+ xguide --> strs[int_vars[ 1 ][ 2 ] ]
88
+ yguide --> strs[int_vars[ 1 ][ 3 ] ]
87
89
if length (vars) > 2
88
- zguide --> vars[ 3 ]
90
+ zguide --> strs[int_vars[ 1 ][ 4 ] ]
89
91
end
90
92
end
91
93
if getindex .(int_vars,1 ) == zeros (length (int_vars)) || getindex .(int_vars,2 ) == zeros (length (int_vars))
@@ -157,7 +159,15 @@ function getsyms(sol)
157
159
end
158
160
end
159
161
160
- function diffeq_to_arrays (sol,plot_analytic,denseplot,plotdensity,tspan,axis_safety,vars,int_vars,tscale,syms)
162
+ cleansyms (syms:: Nothing ) = nothing
163
+ cleansyms (syms:: Vector{Symbol} ) = cleansym .(syms)
164
+ function cleansym (sym:: Symbol )
165
+ str = String (sym)
166
+ replace (str," ₊" => " ." ) # Fix MTK component syntax
167
+ end
168
+ issymbollike (x) = typeof (x) <: Symbol || Symbol (typeof (x)) == :Operation || Symbol (typeof (x)) == :Variable
169
+
170
+ function diffeq_to_arrays (sol,plot_analytic,denseplot,plotdensity,tspan,axis_safety,vars,int_vars,tscale,strs)
161
171
if tspan === nothing
162
172
if sol. tslocation == 0
163
173
end_idx = length (sol)
@@ -228,21 +238,19 @@ function diffeq_to_arrays(sol,plot_analytic,denseplot,plotdensity,tspan,axis_saf
228
238
@assert length (var) == dims
229
239
end
230
240
# Should check that all have the same dims!
231
- plot_vecs,labels = solplot_vecs_and_labels (dims,int_vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,syms )
241
+ plot_vecs,labels = solplot_vecs_and_labels (dims,int_vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,strs )
232
242
end
233
243
234
244
function interpret_vars (vars,sol,syms)
235
245
if vars != = nothing && syms != = nothing
236
246
# Do syms conversion
237
247
tmp_vars = []
238
248
for var in vars
239
- if typeof (var) <: Symbol
240
- var_int = something (findfirst (isequal (var), syms), 0 )
241
- elseif typeof (var) <: Union{Tuple,AbstractArray} # eltype(var) <: Symbol # Some kind of iterable
249
+ if typeof (var) <: Union{Tuple,AbstractArray} # eltype(var) <: Symbol # Some kind of iterable
242
250
tmp = []
243
251
for x in var
244
- if typeof (x) <: Symbol
245
- push! (tmp,something (findfirst (isequal (x ), syms), 0 ))
252
+ if issymbollike (x)
253
+ push! (tmp,something (findfirst (isequal (Symbol (x) ), syms), 0 ))
246
254
else
247
255
push! (tmp,x)
248
256
end
@@ -252,6 +260,8 @@ function interpret_vars(vars,sol,syms)
252
260
else
253
261
var_int = tmp
254
262
end
263
+ elseif issymbollike (var)
264
+ var_int = something (findfirst (isequal (Symbol (var)), syms), 0 )
255
265
else
256
266
var_int = var
257
267
end
@@ -325,14 +335,14 @@ function interpret_vars(vars,sol,syms)
325
335
vars
326
336
end
327
337
328
- function add_labels! (labels,x,dims,sol,syms )
338
+ function add_labels! (labels,x,dims,sol,strs )
329
339
lys = []
330
340
for j in 3 : dims
331
341
if x[j] == 0
332
342
push! (lys," t," )
333
343
else
334
- if syms != = nothing
335
- push! (lys," $(syms [x[j]]) ," )
344
+ if strs != = nothing
345
+ push! (lys," $(strs [x[j]]) ," )
336
346
else
337
347
push! (lys," u$(x[j]) ," )
338
348
end
@@ -342,8 +352,8 @@ function add_labels!(labels,x,dims,sol,syms)
342
352
if x[2 ] == 0 && dims == 3
343
353
tmp_lab = " $(lys... ) (t)"
344
354
else
345
- if syms != = nothing && x[2 ] != 0
346
- tmp = syms [x[2 ]]
355
+ if strs != = nothing && x[2 ] != 0
356
+ tmp = strs [x[2 ]]
347
357
tmp_lab = " ($tmp ,$(lys... ) )"
348
358
else
349
359
if x[2 ] == 0
@@ -361,14 +371,14 @@ function add_labels!(labels,x,dims,sol,syms)
361
371
labels
362
372
end
363
373
364
- function add_analytic_labels! (labels,x,dims,sol,syms )
374
+ function add_analytic_labels! (labels,x,dims,sol,strs )
365
375
lys = []
366
376
for j in 3 : dims
367
377
if x[j] == 0 && dims == 3
368
378
push! (lys," t," )
369
379
else
370
- if syms != = nothing
371
- push! (lys,string (" True " ,syms [x[j]]," ," ))
380
+ if strs != = nothing
381
+ push! (lys,string (" True " ,strs [x[j]]," ," ))
372
382
else
373
383
push! (lys," True u$(x[j]) ," )
374
384
end
@@ -378,8 +388,8 @@ function add_analytic_labels!(labels,x,dims,sol,syms)
378
388
if x[2 ] == 0
379
389
tmp_lab = " $(lys... ) (t)"
380
390
else
381
- if syms != = nothing
382
- tmp = string (" True " ,syms [x[2 ]])
391
+ if strs != = nothing
392
+ tmp = string (" True " ,strs [x[2 ]])
383
393
tmp_lab = " ($tmp ,$(lys... ) )"
384
394
else
385
395
tmp_lab = " (True u$(x[2 ]) ,$(lys... ) )"
@@ -407,7 +417,7 @@ function u_n(timeseries::AbstractArray, n::Int,sol,plott,plot_timeseries)
407
417
end
408
418
end
409
419
410
- function solplot_vecs_and_labels (dims,vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,syms )
420
+ function solplot_vecs_and_labels (dims,vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,strs )
411
421
plot_vecs = []
412
422
labels = String[]
413
423
for x in vars
@@ -427,7 +437,7 @@ function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analyt
427
437
end
428
438
push! (plot_vecs[i],tmp[i])
429
439
end
430
- add_labels! (labels,x,dims,sol,syms )
440
+ add_labels! (labels,x,dims,sol,strs )
431
441
end
432
442
433
443
@@ -445,7 +455,7 @@ function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analyt
445
455
for i in eachindex (tmp)
446
456
push! (plot_vecs[i],tmp[i])
447
457
end
448
- add_analytic_labels! (labels,x,dims,sol,syms )
458
+ add_analytic_labels! (labels,x,dims,sol,strs )
449
459
end
450
460
end
451
461
plot_vecs = [hcat (x... ) for x in plot_vecs]
0 commit comments