244244
245245Plot 2D unstructured Tecplot mesh.
246246"""
247- function plotgrid (head, data, connectivity; ax = nothing , kwargs... )
247+ function plotgrid (head, data, connectivity; ax = nothing , add_decorations = true , kwargs... )
248248 if isnothing (ax)
249249 ax = plt. gca ()
250250 end
@@ -269,8 +269,10 @@ function plotgrid(head, data, connectivity; ax = nothing, kwargs...)
269269 end
270270
271271 ax. set_aspect (" equal" )
272- xlabel (head. variable[1 ])
273- ylabel (head. variable[2 ])
272+ if add_decorations
273+ xlabel (head. variable[1 ])
274+ ylabel (head. variable[2 ])
275+ end
274276
275277 return pc
276278end
@@ -285,7 +287,7 @@ function cutplot(
285287 bd:: BatsrusIDL{3, TV} , var:: AbstractString , ax = nothing ;
286288 plotrange = [- Inf , Inf , - Inf , Inf ], dir = " x" , sequence = 1 ,
287289 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
288- add_colorbar = true , kwargs...
290+ add_colorbar = true , add_decorations = true , kwargs...
289291 ) where {TV}
290292 x, w = bd. x, bd. w
291293 varIndex_ = findindex (bd, var)
@@ -319,21 +321,23 @@ function cutplot(
319321 c = ax. pcolormesh (cut1, cut2, W; norm, kwargs... )
320322 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
321323
322- title (bd. head. wname[varIndex_])
324+ if add_decorations
325+ title (bd. head. wname[varIndex_])
326+
327+ if dir == " x"
328+ xlabel (" y" )
329+ ylabel (" z" )
330+ elseif dir == " y"
331+ xlabel (" x" )
332+ ylabel (" z" )
333+ elseif dir == " z"
334+ xlabel (" x" )
335+ ylabel (" y" )
336+ end
323337
324- if dir == " x"
325- xlabel (" y" )
326- ylabel (" z" )
327- elseif dir == " y"
328- xlabel (" x" )
329- ylabel (" z" )
330- elseif dir == " z"
331- xlabel (" x" )
332- ylabel (" y" )
338+ add_time_iteration! (bd, ax)
333339 end
334340
335- add_time_iteration! (bd, ax)
336-
337341 return c
338342end
339343
@@ -346,7 +350,8 @@ separated with `;`.
346350"""
347351function streamslice (
348352 bd:: BatsrusIDL{3, TV} , var:: AbstractString , ax = nothing ;
349- plotrange = [- Inf , Inf , - Inf , Inf ], dir = " x" , sequence = 1 , kwargs...
353+ plotrange = [- Inf , Inf , - Inf , Inf ], dir = " x" , sequence = 1 ,
354+ add_decorations = true , kwargs...
350355 ) where {TV}
351356 x, w = bd. x, bd. w
352357 varstream = split (var, " ;" )
@@ -393,15 +398,21 @@ function streamslice(
393398 end
394399 s = ax. streamplot (xi, yi, v1' , v2' ; kwargs... )
395400
396- if dir == " x"
397- xlabel (" y" )
398- ylabel (" z" )
399- elseif dir == " y"
400- xlabel (" x" )
401- ylabel (" z" )
402- elseif dir == " z"
403- xlabel (" x" )
404- ylabel (" y" )
401+ if add_decorations
402+ ax. set_title (var)
403+
404+ if dir == " x"
405+ ax. set_xlabel (" y" )
406+ ax. set_ylabel (" z" )
407+ elseif dir == " y"
408+ ax. set_xlabel (" x" )
409+ ax. set_ylabel (" z" )
410+ elseif dir == " z"
411+ ax. set_xlabel (" x" )
412+ ax. set_ylabel (" y" )
413+ end
414+
415+ add_time_iteration! (bd, ax)
405416 end
406417
407418 return s
@@ -416,6 +427,7 @@ function PyPlot.plot(
416427 bd:: BatsrusIDL{1, TV} ,
417428 var:: AbstractString ,
418429 ax = nothing ;
430+ add_decorations = true ,
419431 kwargs...
420432 ) where {TV}
421433 x, w = bd. x, bd. w
@@ -426,9 +438,11 @@ function PyPlot.plot(
426438
427439 c = ax. plot (x, w[:, varIndex_]; kwargs... )
428440
429- xlabel (" x" )
430- ylabel (" $(var) " )
431- add_time_iteration! (bd, ax)
441+ if add_decorations
442+ xlabel (" x" )
443+ ylabel (" $(var) " )
444+ add_time_iteration! (bd, ax)
445+ end
432446
433447 return c
434448end
@@ -464,7 +478,7 @@ function PyPlot.contour(
464478 levels = 0 , plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = 0.1 ,
465479 innermask = false , rbody = nothing ,
466480 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
467- add_colorbar = false , kwargs...
481+ add_colorbar = false , add_decorations = true , kwargs...
468482 ) where {TV}
469483 Xi, Yi, Wi = interp2d (bd, var, plotrange, plotinterval; innermask, rbody)
470484 if isnothing (ax)
@@ -479,7 +493,7 @@ function PyPlot.contour(
479493 end
480494 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
481495
482- add_titles! (bd, var, ax)
496+ add_titles! (bd, var, ax; add_decorations )
483497
484498 return c
485499end
@@ -497,7 +511,7 @@ function PyPlot.contourf(
497511 plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = 0.1 , innermask = false ,
498512 rbody = nothing ,
499513 add_colorbar = true , vmin = - Inf , vmax = Inf , vcenter = 0.0 ,
500- colorscale = :linear , kwargs...
514+ colorscale = :linear , add_decorations = true , kwargs...
501515 ) where {TV}
502516 Xi, Yi, Wi = interp2d (bd, var, plotrange, plotinterval; innermask, rbody)
503517 if isnothing (ax)
@@ -511,7 +525,7 @@ function PyPlot.contourf(
511525 c = ax. contourf (Xi, Yi, Wi; norm, kwargs... )
512526 end
513527 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
514- add_titles! (bd, var, ax)
528+ add_titles! (bd, var, ax; add_decorations )
515529
516530 return c
517531end
@@ -525,7 +539,7 @@ function PyPlot.tricontourf(
525539 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
526540 plotrange = [- Inf , Inf , - Inf , Inf ],
527541 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
528- add_colorbar = true , kwargs...
542+ add_colorbar = true , add_decorations = true , kwargs...
529543 ) where {TV}
530544 x, w = bd. x, bd. w
531545 varIndex_ = findindex (bd, var)
@@ -550,7 +564,7 @@ function PyPlot.tricontourf(
550564 c = ax. tricontourf (X, Y, W; norm, kwargs... )
551565 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
552566
553- add_titles! (bd, var, ax)
567+ add_titles! (bd, var, ax; add_decorations )
554568
555569 return c
556570end
@@ -564,7 +578,7 @@ function PyPlot.tricontour(
564578 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
565579 plotrange = [- Inf , Inf , - Inf , Inf ],
566580 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
567- add_colorbar = false , kwargs...
581+ add_colorbar = false , add_decorations = true , kwargs...
568582 ) where {TV}
569583 x, w = bd. x, bd. w
570584 varIndex_ = findindex (bd, var)
@@ -589,7 +603,7 @@ function PyPlot.tricontour(
589603 c = ax. tricontour (X, Y, W; norm, kwargs... )
590604 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
591605
592- add_titles! (bd, var, ax)
606+ add_titles! (bd, var, ax; add_decorations )
593607
594608 return c
595609end
@@ -624,7 +638,7 @@ Wrapper over `plot_trisurf` in matplotlib.
624638"""
625639function PyPlot. plot_trisurf (
626640 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
627- plotrange = [- Inf , Inf , - Inf , Inf ], kwargs...
641+ plotrange = [- Inf , Inf , - Inf , Inf ], add_decorations = true , kwargs...
628642 ) where {TV}
629643 x, w = bd. x, bd. w
630644 varIndex_ = findindex (bd, var)
@@ -647,7 +661,7 @@ function PyPlot.plot_trisurf(
647661
648662 c = ax. plot_trisurf (X, Y, W; kwargs... )
649663
650- add_titles! (bd, var, ax)
664+ add_titles! (bd, var, ax; add_decorations )
651665
652666 return c
653667end
@@ -663,7 +677,7 @@ function PyPlot.plot_surface(
663677 plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = 0.1 , innermask = false ,
664678 rbody = nothing ,
665679 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
666- add_colorbar = true , kwargs...
680+ add_colorbar = true , add_decorations = true , kwargs...
667681 ) where {TV}
668682 if isnothing (ax)
669683 ax = plt. gca ()
@@ -675,7 +689,7 @@ function PyPlot.plot_surface(
675689 c = plot_surface (Xi, Yi, Wi; norm, kwargs... )
676690 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
677691
678- add_titles! (bd, var, ax)
692+ add_titles! (bd, var, ax; add_decorations )
679693
680694 return c
681695end
@@ -701,7 +715,7 @@ function PyPlot.pcolormesh(
701715 plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = 0.1 , innermask = false ,
702716 rbody = nothing ,
703717 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
704- add_colorbar = true , kwargs...
718+ add_colorbar = true , add_decorations = true , kwargs...
705719 ) where {TV}
706720 xi, yi, Wi = interp2d (bd, var, plotrange, plotinterval; innermask, rbody)
707721
@@ -714,7 +728,7 @@ function PyPlot.pcolormesh(
714728
715729 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
716730
717- add_titles! (bd, var, ax)
731+ add_titles! (bd, var, ax; add_decorations )
718732
719733 return c
720734end
@@ -729,7 +743,7 @@ function PyPlot.tripcolor(
729743 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
730744 plotrange = [- Inf , Inf , - Inf , Inf ], innermask = false , rbody = nothing ,
731745 vmin = - Inf , vmax = Inf , vcenter = 0.0 , colorscale = :linear ,
732- add_colorbar = true , kwargs...
746+ add_colorbar = true , add_decorations = true , kwargs...
733747 ) where {TV}
734748 x, w = bd. x, bd. w
735749
@@ -775,7 +789,7 @@ function PyPlot.tripcolor(
775789 ax. set_xlim (plotrange[1 ], plotrange[2 ])
776790 ax. set_ylim (plotrange[3 ], plotrange[4 ])
777791
778- add_titles! (bd, var, ax)
792+ add_titles! (bd, var, ax; add_decorations )
779793
780794 return c
781795end
@@ -800,7 +814,7 @@ function PyPlot.imshow(
800814 plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = 0.1 , innermask = false ,
801815 rbody = nothing ,
802816 add_colorbar = true , vmin = - Inf , vmax = Inf , vcenter = 0.0 ,
803- colorscale = :linear , kwargs...
817+ colorscale = :linear , add_decorations = true , kwargs...
804818 ) where {
805819 TV,
806820 }
@@ -818,7 +832,7 @@ function PyPlot.imshow(
818832
819833 add_colorbar && colorbar (c; ax, fraction = 0.04 , pad = 0.02 )
820834
821- add_titles! (bd, var, ax)
835+ add_titles! (bd, var, ax; add_decorations )
822836
823837 return c
824838end
@@ -831,15 +845,20 @@ Wrapper over `streamplot` in matplotlib.
831845"""
832846function PyPlot. streamplot (
833847 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
834- plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = Inf , kwargs...
848+ plotrange = [- Inf , Inf , - Inf , Inf ], plotinterval = Inf ,
849+ add_decorations = true , kwargs...
835850 ) where {TV}
836851 xi, yi, v1, v2 = _getvector (bd, var; plotrange, plotinterval)
837852
838853 if isnothing (ax)
839854 ax = plt. gca ()
840855 end
841856
842- return ax. streamplot (xi, yi, v1, v2; kwargs... )
857+ s = ax. streamplot (xi, yi, v1, v2; kwargs... )
858+
859+ add_titles! (bd, var, ax; add_decorations)
860+
861+ return s
843862end
844863
845864function _getvector (
@@ -947,7 +966,7 @@ Wrapper over `quiver` in matplotlib. Only supports Cartesian grid for now.
947966"""
948967function PyPlot. quiver (
949968 bd:: BatsrusIDL{2, TV} , var:: AbstractString , ax = nothing ;
950- stride:: Integer = 10 , kwargs...
969+ stride:: Integer = 10 , add_decorations = true , kwargs...
951970 ) where {TV}
952971 x, w = bd. x, bd. w
953972 VarQuiver = split (var, " ;" )
@@ -965,7 +984,11 @@ function PyPlot.quiver(
965984 ax = plt. gca ()
966985 end
967986
968- return ax. quiver (Xq, Yq, v1q, v2q; kwargs... )
987+ q = ax. quiver (Xq, Yq, v1q, v2q; kwargs... )
988+
989+ add_titles! (bd, var, ax; add_decorations)
990+
991+ return q
969992end
970993
971994"""
@@ -1019,13 +1042,24 @@ function set_colorbar(colorscale::Symbol, vmin, vmax, data = [1.0]; vcenter = 0.
10191042 return cnorm
10201043end
10211044
1022- function add_titles! (bd:: BatsrusIDL , var, ax)
1023- varIndex_ = findindex (bd, var)
1024- title (bd. head. wname[varIndex_])
1045+ function add_titles! (bd:: BatsrusIDL , var, ax; add_decorations = true )
1046+ add_decorations || return
10251047
1026- xlabel (bd. head. coord[1 ])
1027- ylabel (bd. head. coord[2 ])
1028- return add_time_iteration! (bd, ax)
1048+ varstr = string (var)
1049+ vars = split (varstr, " ;" )
1050+ varIndex_ = findindex (bd, vars[1 ])
1051+
1052+ if length (vars) > 1
1053+ ax. set_title (varstr)
1054+ else
1055+ ax. set_title (bd. head. wname[varIndex_])
1056+ end
1057+
1058+ ax. set_xlabel (bd. head. coord[1 ])
1059+ ax. set_ylabel (bd. head. coord[2 ])
1060+ add_time_iteration! (bd, ax)
1061+
1062+ return
10291063end
10301064
10311065function add_time_iteration! (bd:: BatsrusIDL , ax)
0 commit comments