Skip to content

Commit

Permalink
add xlims and ylims
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed May 3, 2024
1 parent 6489843 commit 171acf5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/ControlPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mutable struct PlotX
xlabel
ylabels
ysize
xlims
ylims
fig
type::Int64
end
Expand All @@ -27,7 +29,7 @@ function load(filename::String)
end

function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="",
labels=nothing, fig="", ysize=14, disp=false)
labels=nothing, xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig)
Expand Down Expand Up @@ -55,15 +57,15 @@ function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="",
else
println("OK")
end
PlotX(X, Ys, labels, xlabel, ylabel, ysize, fig, 4)
PlotX(X, Ys, labels, xlabel, ylabel, ysize, xlims, ylims, 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="", fig="", ysize=14, disp=false)
function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig)
Expand All @@ -77,10 +79,10 @@ function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", ysiz
plt.grid(true)
plt.tight_layout()
end
PlotX(X, Y, nothing, xlabel, ylabel, ysize, fig, 1)
PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, fig, 1)
end

function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", ysize=14, disp=false)
function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, xlims=nothing, ylims=nothing, fig="", title="", ysize=14, disp=false)
if disp
len=length(Y)
fig_ = plt.figure(fig, figsize=(8, len*2))
Expand Down Expand Up @@ -114,10 +116,10 @@ function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", ys

plt.tight_layout()
end
PlotX(collect(X), Y, nothing, xlabel, ylabels, ysize, fig, 2)
PlotX(collect(X), Y, nothing, xlabel, ylabels, ysize, xlims, ylims, fig, 2)
end

function plotxy(X, Y; xlabel="", ylabel="", fig="", ysize=14, disp=false)
function plotxy(X, Y; xlabel="", ylabel="", xlims=nothing, ylims=nothing, fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig, figsize=(6,6))
Expand All @@ -128,18 +130,18 @@ function plotxy(X, Y; xlabel="", ylabel="", fig="", ysize=14, disp=false)
plt.grid(true)
plt.tight_layout()
end
PlotX(X, Y, nothing, xlabel, ylabel, ysize, fig, 3)
PlotX(X, Y, nothing, xlabel, ylabel, ysize, xlims, ylims, fig, 3)
end

function display(P::PlotX)
if P.type == 1
plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, 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, fig=P.fig, ysize=P.ysize, disp=true)
elseif P.type == 2
plotx(P.X, P.Y...; xlabel=P.xlabel, ylabels=P.ylabels, 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, fig=P.fig, ysize=P.ysize, disp=true)
elseif P.type == 3
plotxy(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, 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, fig=P.fig, ysize=P.ysize, disp=true)
else
plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, labels=P.labels, 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, fig=P.fig, ysize=P.ysize, disp=true)
end
plt.pause(0.01)
plt.show(block=false)
Expand Down

0 comments on commit 171acf5

Please sign in to comment.