diff --git a/mwes/mwe_03.jl b/mwes/mwe_03.jl index 8d90887..c61a428 100644 --- a/mwes/mwe_03.jl +++ b/mwes/mwe_03.jl @@ -6,4 +6,6 @@ x_max = maximum(x) z_max = maximum(z) xlabel = "x [m]" -p=plot(x, z; xlabel, ylabel="z [m]", xlims = (x_max-15.0, x_max+5), ylims = (z_max-15.0, z_max+5)) \ No newline at end of file +reltime = 0.0 +ann = (x_max-10.0, z_max-3.0, "t=$(round(reltime,digits=1)) s") +p=plot(x, z; xlabel, ylabel="z [m]", xlims = (x_max-15.0, x_max+5), ylims = (z_max-15.0, z_max+5), ann) \ No newline at end of file diff --git a/src/ControlPlots.jl b/src/ControlPlots.jl index 9b8487d..353ff86 100644 --- a/src/ControlPlots.jl +++ b/src/ControlPlots.jl @@ -16,6 +16,7 @@ mutable struct PlotX ysize xlims ylims + ann fig type::Int64 end @@ -29,7 +30,7 @@ function load(filename::String) end function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="", - labels=nothing, xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false) + labels=nothing, xlims=nothing, ylims=nothing, ann=nothing, fig="", ysize=14, disp=false) if disp if fig != "" plt.figure(fig) @@ -61,7 +62,7 @@ function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="", else println("OK") end - PlotX(X, Ys, labels, xlabel, ylabel, ysize, xlims, ylims, fig, 4) + PlotX(X, Ys, labels, xlabel, ylabel, ysize, xlims, ylims, ann, fig, 4) end function plot(Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", ysize=14, disp=false) @@ -69,7 +70,7 @@ function plot(Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", ysize=1 plot(X, Y; xlabel, ylabel, fig, disp, ysize) end -function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false) +function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", xlims=nothing, ylims=nothing, ann=nothing, fig="", ysize=14, disp=false) if disp if fig != "" plt.figure(fig) @@ -87,13 +88,16 @@ function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", xlims=nothin if ! isnothing(ylims) plt.ylim(ylims) end + if ! isnothing(ann) + plt.annotate(ann[3], xy=(ann[1], ann[2]), fontsize = 14) + end plt.grid(true) plt.tight_layout() end - PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, fig, 1) + PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, ann, fig, 1) end -function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, xlims=nothing, ylims=nothing, fig="", title="", ysize=14, disp=false) +function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, xlims=nothing, ylims=nothing, ann=nothing, fig="", title="", ysize=14, disp=false) if disp len=length(Y) fig_ = plt.figure(fig, figsize=(8, len*2)) @@ -127,10 +131,10 @@ function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, xlims=nothing, ylims plt.tight_layout() end - PlotX(collect(X), Y, nothing, xlabel, ylabels, ysize, xlims, ylims, fig, 2) + PlotX(collect(X), Y, nothing, xlabel, ylabels, ysize, xlims, ylims, ann, fig, 2) end -function plotxy(X, Y; xlabel="", ylabel="", xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false) +function plotxy(X, Y; xlabel="", ylabel="", xlims=nothing, ylims=nothing, ann=nothing, fig="", ysize=14, disp=false) if disp if fig != "" plt.figure(fig, figsize=(6,6)) @@ -141,18 +145,18 @@ function plotxy(X, Y; xlabel="", ylabel="", xlims=nothing, ylims=nothing, fig="" plt.grid(true) plt.tight_layout() end - PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, fig, 3) + PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, ann, fig, 3) end function display(P::PlotX) if P.type == 1 - plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, xlims=P.xlims, ylims=P.ylims, fig=P.fig, ysize=P.ysize, disp=true) + plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, xlims=P.xlims, ylims=P.ylims, ann=P.ann, fig=P.fig, ysize=P.ysize, disp=true) elseif P.type == 2 - plotx(P.X, P.Y...; xlabel=P.xlabel, ylabels=P.ylabels, xlims=P.xlims, ylims=P.ylims, fig=P.fig, ysize=P.ysize, disp=true) + plotx(P.X, P.Y...; xlabel=P.xlabel, ylabels=P.ylabels, xlims=P.xlims, ylims=P.ylims, ann=P.ann, fig=P.fig, ysize=P.ysize, disp=true) elseif P.type == 3 - plotxy(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, xlims=P.xlims, ylims=P.ylims, fig=P.fig, ysize=P.ysize, disp=true) + plotxy(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, xlims=P.xlims, ylims=P.ylims, ann=P.ann, fig=P.fig, ysize=P.ysize, disp=true) else - plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, labels=P.labels, xlims=P.xlims, ylims=P.ylims, fig=P.fig, ysize=P.ysize, disp=true) + plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, labels=P.labels, xlims=P.xlims, ylims=P.ylims, ann=P.ann, fig=P.fig, ysize=P.ysize, disp=true) end plt.pause(0.01) plt.show(block=false)