Skip to content

Commit

Permalink
some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ufechner7 committed Mar 17, 2024
1 parent 6031406 commit 3dd319d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ p = load("plot.jld2")
```
The plot is automatically displayed.

### Multi-channel plot
```julia
using PyPlotX

T = 0:0.1:2pi
X = sin.(T)
Y = cos.(T)
p = plotx(T, X, Y);
```

### XY-Plot
```julia
using PyPlotX
Expand Down
6 changes: 6 additions & 0 deletions examples/multi-channel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using PyPlotX

T = 0:0.1:2pi
X = sin.(T)
Y = cos.(T)
p = plotx(collect(T), X, Y);
20 changes: 20 additions & 0 deletions mwes/mwe_02.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using JLD2

mutable struct PlotX
X
Y
end

function test(X, Y...)
len=length(Y)
println(len)
println(typeof(Y))
PlotX(X, Y)
end

T = 0:0.1:2pi
X = sin.(T)
Y = cos.(T)
p1 = test(T, X, Y);
p2 = test(p1.X, p1.Y...);
nothing
30 changes: 17 additions & 13 deletions src/PyPlotX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import JLD2

export plot, plotx, plotxy, plt, load, save

mutable struct Plot
mutable struct PlotX
X
Y
labels
fig
type::Int64
end

function save(filename::String, p::Plot)
function save(filename::String, p::PlotX)
JLD2.save(filename, "plot", p)
end

Expand All @@ -30,7 +30,7 @@ function plot(X, Y; label="", fig="")
plt.plot(X, Y; label)
plt.grid(true)
plt.tight_layout()
Plot(X, Y, label, fig, 1)
PlotX(X, Y, label, fig, 1)
end

function plotx(X, Y...; labels=nothing, fig="", title="")
Expand All @@ -40,7 +40,11 @@ function plotx(X, Y...; labels=nothing, fig="", title="")
ax=[]
for y in Y
subplot=100len+10+i
push!(ax, plt.subplot(subplot))
if i==1
push!(ax, plt.subplot(subplot))
else
push!(ax, plt.subplot(subplot, sharex=ax[1]))
end
if i==1
plt.suptitle(title, fontsize=14) # Super title
end
Expand All @@ -50,14 +54,18 @@ function plotx(X, Y...; labels=nothing, fig="", title="")
lbl=""
end
plt.plot(X, y, label=lbl)
plt.xlim(0, X[end])
plt.ylabel(lbl, fontsize=14);
plt.grid(true)
if i < len
plt.setp(ax[i].get_xticklabels(), visible=false)
end
i+=1
end
plt.xlabel("time [s]", fontsize=14)
plt.xlim(0, X[end])

plt.tight_layout()
Plot(X, Y, labels, fig, 2)
PlotX(collect(X), Y, labels, fig, 2)
end

function plotxy(X, Y; xlabel="", ylabel="", fig="")
Expand All @@ -69,22 +77,18 @@ function plotxy(X, Y; xlabel="", ylabel="", fig="")
plt.ylabel(ylabel, fontsize=14);
plt.grid(true)
plt.tight_layout()
Plot(X, Y, [xlabel, ylabel], fig, 3)
PlotX(X, Y, [xlabel, ylabel], fig, 3)
end

function plot(P::Plot)
function display(P::PlotX)
if P.type == 1
plot(P.X, P.Y; label=P.labels, fig=P.fig)
elseif P.type == 2
plotx(P.X, P.Y; labels=P.labels, fig=P.fig)
plotx(P.X, P.Y...; labels=P.labels, fig=P.fig)
else
plotxy(P.X, P.Y; xlabel=P.labels[1], ylabel=P.labels[2])
end
nothing
end

function display(P::Plot)
plot(P)
end

end

0 comments on commit 3dd319d

Please sign in to comment.