diff --git a/test/plot.jl b/test/plot.jl index 6c00dd97..a2e27b0d 100644 --- a/test/plot.jl +++ b/test/plot.jl @@ -24,72 +24,28 @@ function plotxy(X, Y; xlabel="", ylabel, fig="") plt.tight_layout() end -function plot2(X, Y1, Y2; labels=["", ""], fig="", title="") +function plotx(X, Y...; labels=nothing, fig="", title="") + len=length(Y) fig_ = plt.figure(fig, figsize=(8, 6)) - ax1 = plt.subplot(211) - plt.suptitle(title, fontsize=14) # Super title - plt.plot(X, Y1, label=labels[1]); - plt.ylabel(labels[1], fontsize=14); - plt.grid(true) - plt.setp(ax1.get_xticklabels(), visible=false) - ax2 = plt.subplot(212, sharex = ax1) - plt.plot(X, Y2, label=labels[2]) - plt.grid(true) - plt.ylabel(labels[2], fontsize=14); - plt.grid(true) - plt.xlabel("time [s]", fontsize=14) - plt.xlim(0, X[end]) - plt.tight_layout() -end - -function plot3(X, Y1, Y2, Y3; labels=["", "", ""], fig="", title="") - fig_ = plt.figure(fig, figsize=(8, 6)) - ax1 = plt.subplot(311) - plt.suptitle(title, fontsize=14) # Super title - plt.plot(X, Y1, label=labels[1]); - plt.ylabel(labels[1], fontsize=14); - plt.grid(true) - plt.setp(ax1.get_xticklabels(), visible=false) - ax2 = plt.subplot(312, sharex = ax1) - plt.plot(X, Y2, label=labels[2]) - plt.grid(true) - plt.ylabel(labels[2], fontsize=14); - plt.grid(true) - plt.setp(ax2.get_xticklabels(), visible=false) - ax3 = plt.subplot(313, sharex = ax1) - plt.plot(X, Y3, label=labels[3]) - plt.grid(true) - plt.ylabel(labels[3], fontsize=14); - plt.grid(true) + i=1 + ax=[] + for y in Y + subplot=100len+10+i + push!(ax, plt.subplot(subplot)) + if i==1 + plt.suptitle(title, fontsize=14) # Super title + end + if ! isnothing(labels) + lbl=labels[i] + else + lbl="" + end + plt.plot(X, y, label=lbl) + plt.ylabel(lbl, fontsize=14); + plt.grid(true) + i+=1 + end plt.xlabel("time [s]", fontsize=14) plt.xlim(0, X[end]) plt.tight_layout() end - -function plot4(X, Y1, Y2, Y3, Y4; labels=["", "", "", ""], fig="", title="") - fig_ = plt.figure(fig, figsize=(8, 6)) - ax1 = plt.subplot(311) - plt.suptitle(title, fontsize=14) # Super title - plt.plot(X, Y1, label=labels[1]); - ylabel(labels[1], fontsize=14); - plt.grid(true) - plt.setp(ax1.get_xticklabels(), visible=false) - ax2 = plt.subplot(312, sharex = ax1) - plt.plot(X, Y2, label=labels[2]) - plt.grid(true) - ylabel(labels[2], fontsize=14); grid(true) - plt.setp(ax2.get_xticklabels(), visible=false) - ax3 = plt.subplot(313, sharex = ax1) - plt.plot(X, Y3, label=labels[3]) - plt.grid(true) - plt.ylabel(labels[3], fontsize=14); - plt.grid(true) - ax4 = plt.subplot(313, sharex = ax1) - plt.plot(X, Y4, label=labels[4]) - plt.grid(true) - plt.ylabel(labels[4], fontsize=14); - plt.grid(true) - plt.xlabel("time [s]", fontsize=14) - plt.xlim(0, X[end]) - plt.tight_layout() -end \ No newline at end of file diff --git a/test/test_flightpathcontroller1.jl b/test/test_flightpathcontroller1.jl index 129557ae..87962fc9 100644 --- a/test/test_flightpathcontroller1.jl +++ b/test/test_flightpathcontroller1.jl @@ -42,7 +42,7 @@ end include("plot.jl") -plot3(TIME, PSI, BETA, PSI_DOT; +plotx(TIME, PSI, BETA, PSI_DOT; labels=["heading angle psi [°]","elevation β [°]", "psi_dot [rad/s]"], fig = "test_fpc1") diff --git a/test/test_flightpathcontroller2.jl b/test/test_flightpathcontroller2.jl index 4f27fd7f..3124647b 100644 --- a/test/test_flightpathcontroller2.jl +++ b/test/test_flightpathcontroller2.jl @@ -56,7 +56,7 @@ for i in 1:SAMPLES on_timer(kite) end include("plot.jl") -plot3(TIME, PSI, BETA, PSI_DOT; +plotx(TIME, PSI, BETA, PSI_DOT; labels=["heading angle psi [°]", "elevation β [°]", "psi_dot [rad/s]"], fig="test_fpc2") diff --git a/test/test_forcespeedcontroller1.jl b/test/test_forcespeedcontroller1.jl index 9f3e402d..cd5cd243 100644 --- a/test/test_forcespeedcontroller1.jl +++ b/test/test_forcespeedcontroller1.jl @@ -56,15 +56,15 @@ for i in 1:SAMPLES end include("plot.jl") -plot3(TIME, V_WIND, V_RO, V_SET_OUT, +plotx(TIME, V_WIND, V_RO, V_SET_OUT, labels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]"], fig="test_forcespeed_1a") -plot2(TIME, F_ERR*0.001, V_ERR, +plotx(TIME, F_ERR*0.001, V_ERR, labels=["f_err [kN]", "v_error [m/s"], fig="test_forcespeed_1b") -plot2(TIME, ACC, FORCE*0.001, +plotx(TIME, ACC, FORCE*0.001, labels=["acc [m/s²]", "force [kN]"], fig="test_forcespeed_1c") diff --git a/test/test_forcespeedcontroller2.jl b/test/test_forcespeedcontroller2.jl index cafac4c9..7f3fa554 100644 --- a/test/test_forcespeedcontroller2.jl +++ b/test/test_forcespeedcontroller2.jl @@ -67,15 +67,15 @@ for i in 1:SAMPLES speed_controller_step4!(pid1, pid2, pid3, mix3, winch, calc, i, last_force, last_v_set_out, V_WIND, STARTUP, V_RO, ACC, FORCE, V_SET_OUT, STATE, V_ERR, F_ERR) end -plot3(TIME, V_WIND, V_RO, V_SET_OUT; +plotx(TIME, V_WIND, V_RO, V_SET_OUT; labels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]"], fig="test_forcespeed_2a") -plot2(TIME, F_ERR*0.001, V_ERR; +plotx(TIME, F_ERR*0.001, V_ERR; labels=["f_err [kN]", "v_error [m/s]"], fig="test_forcespeed_2b") -plot3(TIME, ACC, FORCE*0.001, STATE; +plotx(TIME, ACC, FORCE*0.001, STATE; labels=["acc [m/s²]", "force [kN]", "state"], fig="test_forcespeed_2c")