Skip to content

Commit

Permalink
add param ysize
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Apr 12, 2024
1 parent fbba2ea commit b2b6c9e
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/ControlPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mutable struct PlotX
labels
xlabel
ylabels
ysize
fig
type::Int64
end
Expand All @@ -26,7 +27,7 @@ function load(filename::String)
end

function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="",
labels=nothing, fig="", disp=false)
labels=nothing, fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig)
Expand All @@ -46,23 +47,23 @@ function plot(X, Ys::AbstractVector{<:AbstractVector}; xlabel="", ylabel="",
plt.xlabel(xlabel, fontsize=14);
end
if ylabel != ""
plt.ylabel(ylabel, fontsize=14);
plt.ylabel(ylabel, fontsize=ysize);
end
plt.grid(true)
plt.legend()
plt.tight_layout()
else
println("OK")
end
PlotX(X, Ys, labels, xlabel, ylabel, fig, 4)
PlotX(X, Ys, labels, xlabel, ylabel, ysize, fig, 4)
end

function plot(Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", disp=false)
function plot(Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", ysize=14, disp=false)
X = 1:length(Y)
plot(X, Y; xlabel, ylabel, fig, disp)
plot(X, Y; xlabel, ylabel, fig, disp, ysize)
end

function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", disp=false)
function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig)
Expand All @@ -71,15 +72,15 @@ function plot(X, Y::AbstractVector{<:Number}; xlabel="", ylabel="", fig="", disp
if xlabel != ""
plt.xlabel(xlabel, fontsize=14);
end
plt.ylabel(ylabel, fontsize=14);
plt.ylabel(ylabel; fontsize=ysize);
plt.xlim(X[begin], X[end])
plt.grid(true)
plt.tight_layout()
end
PlotX(X, Y, nothing, xlabel, ylabel, fig, 1)
PlotX(X, Y, nothing, xlabel, ylabel, ysize, fig, 1)
end

function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", disp=false)
function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", ysize=14, disp=false)
if disp
len=length(Y)
fig_ = plt.figure(fig, figsize=(8, len*2))
Expand All @@ -93,7 +94,7 @@ function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", di
push!(ax, plt.subplot(subplot, sharex=ax[1]))
end
if i==1
plt.suptitle(title, fontsize=14) # Super title
plt.suptitle(title; fontsize=14) # Super title
end
if ! isnothing(ylabels)
lbl=ylabels[i]
Expand All @@ -102,7 +103,7 @@ function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", di
end
plt.plot(X, y, label=lbl)
plt.xlim(X[begin], X[end])
plt.ylabel(lbl, fontsize=14);
plt.ylabel(lbl; fontsize=ysize);
plt.grid(true)
if i < len
plt.setp(ax[i].get_xticklabels(), visible=false)
Expand All @@ -113,32 +114,32 @@ function plotx(X, Y...; xlabel="time [s]", ylabels=nothing, fig="", title="", di

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

function plotxy(X, Y; xlabel="", ylabel="", fig="", disp=false)
function plotxy(X, Y; xlabel="", ylabel="", fig="", ysize=14, disp=false)
if disp
if fig != ""
plt.figure(fig, figsize=(6,6))
end
plt.plot(X, Y)
plt.xlabel(xlabel, fontsize=14);
plt.ylabel(ylabel, fontsize=14);
plt.ylabel(ylabel, fontsize=ysize);
plt.grid(true)
plt.tight_layout()
end
PlotX(X, Y, nothing, xlabel, ylabel, fig, 3)
PlotX(X, Y, nothing, xlabel, ylabel, ysize, 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, disp=true)
plot(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, 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, disp=true)
plotx(P.X, P.Y...; xlabel=P.xlabel, ylabels=P.ylabels, 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, disp=true)
plotxy(P.X, P.Y; xlabel=P.xlabel, ylabel=P.ylabels, fig=P.fig, ysize=P.ysize, disp=true)
else
plot(P.X, P.Y; xlabel=P.xlabel, labels=P.labels, fig=P.fig, disp=true)
plot(P.X, P.Y; xlabel=P.xlabel, labels=P.labels, fig=P.fig, ysize=P.ysize, disp=true)
end
plt.pause(0.01)
plt.show(block=false)
Expand Down

0 comments on commit b2b6c9e

Please sign in to comment.