Skip to content

Commit

Permalink
add ann
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed May 3, 2024
1 parent 84f38ef commit a9643ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion mwes/mwe_03.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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)
28 changes: 16 additions & 12 deletions src/ControlPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mutable struct PlotX
ysize
xlims
ylims
ann
fig
type::Int64
end
Expand All @@ -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)
Expand Down Expand Up @@ -61,15 +62,15 @@ 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)
X = 1:length(Y)
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)
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit a9643ae

Please sign in to comment.