Alternative: CMDimData.jl
If you would prefer a system that has built-in support for multi-dimensional datasets, for example:
You are simulating something while varying multiple parameters
⇘
…so you can find out how they affect the outcome by plotting/post-processing data
Then you might want to try out CMDimData.jl:
→ GitHub - ma-laforge/CMDimData.jl: Parametric analysis/visualization +continuous-f(x) interpolation
It basically handles the “for” loop things for you when you plot, or run calculations (using MDDatasets.jl in the background). You just need to first get your data in a special DataRS recursive structure.
Example plotting without needing “for” loops
Sorry, I couldn’t get useful multi-dimensional data from your example, which is a bit confusing. So I “ported” the example from @BLI, more-or-less.
using CMDimData, MDDatasets, CMDimData.EasyPlot #Toolset
CMDimData.@includepkg EasyPlotInspect #Use InspectDR backend
Tsim = 2e-3 #End time of "Simulation"
t = DataF1(range(0,Tsim,length=1000)) #DataF1: Special {x,y} structure
#Generate data using a recursive structure for each "swept parameter":
ydata = fill(DataRS{DataF1}, PSweep("freq", [1, 2, 4, 8, 16] .* 1e3)) do 𝑓
𝜔 = 2π*𝑓; T = 1/𝑓; 𝜙 = 0; A = 1.2
sig = A * sin(𝜔*t + 𝜙)
return sig
end;
#Describe plot (more control required than Plot.jl)
#------------------------------------------------------------------------------
plot = cons(:plot, title = "multi-dimensional data",
xyaxes = set(xscale=:lin, yscale=:lin),
labels = set(xaxis="X-Axis Label", yaxis="Y-Axis Label")
)
#Add ydata to plot:
push!(plot,
cons(:wfrm, ydata, label="ydata"),
)
#Easily derive other quantities from data:
push!(plot,
cons(:wfrm, xscale(ydata, 2)+3, label="xscaled+yshifted"),
cons(:wfrm, xshift(ydata, 4e-3)-3, label="xshifted+yshifted"),
cons(:wfrm, deriv(ydata/40e3)-6, label="dy/dt+yshifted"),
)
#Display plot itself:
EasyPlot.displaygui(:InspectDR, plot) #Can use other backends
Comments (downsides)
- You can use PyPlot.jl or Plots.jl as a backend, but InspectDR.jl has the best support.
- You might need to learn the CMDimData.EasyPlot API to get better control on plots.
- You might need to learn the MDDatasets.jl API to see what is possible with its data encapsulation.
- Overall API is not stabilized, an will likely change in the future (I don’t seem to change it often, though).