@@ -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
86
if typeof (vars) <: Tuple && (typeof (vars[1 ]) == Symbol && typeof (vars[2 ]) == Symbol)
85
- xguide --> vars[ 1 ]
86
- yguide --> 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,14 @@ 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
+
169
+ function diffeq_to_arrays (sol,plot_analytic,denseplot,plotdensity,tspan,axis_safety,vars,int_vars,tscale,strs)
161
170
if tspan === nothing
162
171
if sol. tslocation == 0
163
172
end_idx = length (sol)
@@ -228,32 +237,32 @@ function diffeq_to_arrays(sol,plot_analytic,denseplot,plotdensity,tspan,axis_saf
228
237
@assert length (var) == dims
229
238
end
230
239
# 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 )
240
+ plot_vecs,labels = solplot_vecs_and_labels (dims,int_vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,strs )
232
241
end
233
242
234
243
function interpret_vars (vars,sol,syms)
235
244
if vars != = nothing && syms != = nothing
236
245
# Do syms conversion
237
246
tmp_vars = []
238
247
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
248
+ if typeof (var) <: Union{Tuple,AbstractArray} # eltype(var) <: Symbol # Some kind of iterable
242
249
tmp = []
243
250
for x in var
244
- if typeof (x) <: Symbol
245
- push! (tmp,something (findfirst (isequal (x), syms), 0 ))
246
- else
251
+ if typeof (x) <: Integer
247
252
push! (tmp,x)
253
+ else
254
+ push! (tmp,something (findfirst (isequal (Symbol (x)), syms), 0 ))
248
255
end
249
256
end
250
257
if typeof (var) <: Tuple
251
258
var_int = tuple (tmp... )
252
259
else
253
260
var_int = tmp
254
261
end
255
- else
262
+ elseif typeof (var) <: Integer
256
263
var_int = var
264
+ else
265
+ var_int = something (findfirst (isequal (Symbol (var)), syms), 0 )
257
266
end
258
267
push! (tmp_vars,var_int)
259
268
end
@@ -325,14 +334,14 @@ function interpret_vars(vars,sol,syms)
325
334
vars
326
335
end
327
336
328
- function add_labels! (labels,x,dims,sol,syms )
337
+ function add_labels! (labels,x,dims,sol,strs )
329
338
lys = []
330
339
for j in 3 : dims
331
340
if x[j] == 0
332
341
push! (lys," t," )
333
342
else
334
- if syms != = nothing
335
- push! (lys," $(syms [x[j]]) ," )
343
+ if strs != = nothing
344
+ push! (lys," $(strs [x[j]]) ," )
336
345
else
337
346
push! (lys," u$(x[j]) ," )
338
347
end
@@ -342,8 +351,8 @@ function add_labels!(labels,x,dims,sol,syms)
342
351
if x[2 ] == 0 && dims == 3
343
352
tmp_lab = " $(lys... ) (t)"
344
353
else
345
- if syms != = nothing && x[2 ] != 0
346
- tmp = syms [x[2 ]]
354
+ if strs != = nothing && x[2 ] != 0
355
+ tmp = strs [x[2 ]]
347
356
tmp_lab = " ($tmp ,$(lys... ) )"
348
357
else
349
358
if x[2 ] == 0
@@ -361,14 +370,14 @@ function add_labels!(labels,x,dims,sol,syms)
361
370
labels
362
371
end
363
372
364
- function add_analytic_labels! (labels,x,dims,sol,syms )
373
+ function add_analytic_labels! (labels,x,dims,sol,strs )
365
374
lys = []
366
375
for j in 3 : dims
367
376
if x[j] == 0 && dims == 3
368
377
push! (lys," t," )
369
378
else
370
- if syms != = nothing
371
- push! (lys,string (" True " ,syms [x[j]]," ," ))
379
+ if strs != = nothing
380
+ push! (lys,string (" True " ,strs [x[j]]," ," ))
372
381
else
373
382
push! (lys," True u$(x[j]) ," )
374
383
end
@@ -378,8 +387,8 @@ function add_analytic_labels!(labels,x,dims,sol,syms)
378
387
if x[2 ] == 0
379
388
tmp_lab = " $(lys... ) (t)"
380
389
else
381
- if syms != = nothing
382
- tmp = string (" True " ,syms [x[2 ]])
390
+ if strs != = nothing
391
+ tmp = string (" True " ,strs [x[2 ]])
383
392
tmp_lab = " ($tmp ,$(lys... ) )"
384
393
else
385
394
tmp_lab = " (True u$(x[2 ]) ,$(lys... ) )"
@@ -407,7 +416,7 @@ function u_n(timeseries::AbstractArray, n::Int,sol,plott,plot_timeseries)
407
416
end
408
417
end
409
418
410
- function solplot_vecs_and_labels (dims,vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,syms )
419
+ function solplot_vecs_and_labels (dims,vars,plot_timeseries,plott,sol,plot_analytic,plot_analytic_timeseries,strs )
411
420
plot_vecs = []
412
421
labels = String[]
413
422
for x in vars
@@ -427,7 +436,7 @@ function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analyt
427
436
end
428
437
push! (plot_vecs[i],tmp[i])
429
438
end
430
- add_labels! (labels,x,dims,sol,syms )
439
+ add_labels! (labels,x,dims,sol,strs )
431
440
end
432
441
433
442
@@ -445,7 +454,7 @@ function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analyt
445
454
for i in eachindex (tmp)
446
455
push! (plot_vecs[i],tmp[i])
447
456
end
448
- add_analytic_labels! (labels,x,dims,sol,syms )
457
+ add_analytic_labels! (labels,x,dims,sol,strs )
449
458
end
450
459
end
451
460
plot_vecs = [hcat (x... ) for x in plot_vecs]
0 commit comments