Skip to content

Commit c46c2e8

Browse files
committed
Migrate examples for PyPlot to CairoMakie
1 parent f90a7a8 commit c46c2e8

14 files changed

+86
-116
lines changed

src/examples/julia/batch.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
include("config.jl")
55

@@ -58,11 +58,10 @@ uLastPeriod = readFrames(rp, currentFrame(rp), 2)
5858
masterTrigger!(rp, false)
5959
serverMode!(rp, CONFIGURATION)
6060

61-
figure(1)
62-
clf()
6361
# Frame dimensions are [samples, chan, periods, frames]
64-
plot(vec(uFirstPeriod[:,1,:,:]))
65-
plot(vec(uCurrentPeriod[:,1,:,:]))
66-
plot(vec(uLastPeriod[:,1,:,:]))
67-
legend(("first period", "current period", "last period"))
68-
savefig("images/batch.png")
62+
plot = lines(vec(uFirstPeriod[:,1,:,:]), label = "first period")
63+
lines!(plot.axis, vec(uCurrentPeriod[:,1,:,:]), label = "current period")
64+
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "last period")
65+
axislegend(plot.axis)
66+
save(joinpath(@__DIR__(), "images", "batch.png"), plot)
67+
plot

src/examples/julia/cluster.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
# obtain the URL of the RedPitaya
55
include("config.jl")
@@ -44,14 +44,12 @@ uCurrentPeriod = readFrames(rpc, currentFrame(rpc), 1)
4444
masterTrigger!(rpc, false)
4545
serverMode!(rpc, CONFIGURATION)
4646

47-
figure(1)
48-
clf()
49-
subplot(2, 1, 1)
50-
plot(vec(uFirstPeriod[:,1,:,:]))
51-
plot(vec(uFirstPeriod[:,3,:,:]))
52-
legend(("Channel 1", "Channel 3"))
53-
subplot(2, 1, 2)
54-
plot(vec(uCurrentPeriod[:,1,:,:]))
55-
plot(vec(uCurrentPeriod[:,3,:,:]))
56-
legend(("Channel 1", "Channel 3"))
57-
savefig("images/cluster.png")
47+
fig = Figure()
48+
plot = lines(fig[1,1], vec(uFirstPeriod[:,1,:,:]), label = "Channel 1")
49+
lines!(plot.axis, vec(uFirstPeriod[:,3,:,:]), label = "Channel 3")
50+
axislegend(plot.axis)
51+
plot = lines(fig[1, 2], vec(uCurrentPeriod[:,1,:,:]), label = "Channel 1")
52+
lines!(plot.axis, vec(uCurrentPeriod[:,3,:,:]), label = "Channel 3")
53+
axislegend(plot.axis)
54+
save(joinpath(@__DIR__(), "images", "cluster.png"), fig)
55+
fig

src/examples/julia/clusterView.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
include("config.jl")
55

@@ -46,12 +46,7 @@ sleep(1.0)
4646
# ClusterView only reads from selected RedPitayas
4747
uCurrentPeriod = readData(rpcv, currentFrame(rpc), 1)
4848

49-
fig = figure(1)
50-
clf()
51-
subplot(1,2,1)
52-
plot(vec(uCurrentPeriod[:,1,:,:]))
49+
fig = Figure()
5350
# Channels from result can be mapped to channels in the cluster
54-
PyPlot.title("Cluster channel $(viewToClusterChannel(rpcv,1))")
55-
subplot(1,2,2)
56-
plot(vec(uCurrentPeriod[:,3,:,:]))
57-
PyPlot.title("Cluster channel $(viewToClusterChannel(rpcv,3))")
51+
lines(fig[1, 1], vec(uCurrentPeriod[:,1,:,:]), axis = (title = "Cluster channel $(viewToClusterChannel(rpcv,1))",))
52+
lines(fig[1, 2], vec(uCurrentPeriod[:,3,:,:]), axis = (title = "Cluster channel $(viewToClusterChannel(rpcv,3))",))

src/examples/julia/config.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# URLs= ["rp-f08ccb.local", "rp-f08caa.local"]
2-
URLs= ["192.168.2.22"]#, "192.168.2.17"]
2+
URLs= ["192.168.1.100"]#, "192.168.2.17"]
33
mkpath("images")

src/examples/julia/counterTrigger.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33
using Statistics
44
using Base.Threads
55

@@ -108,15 +108,12 @@ counterTrigger_enabled!(rp, false)
108108

109109
close(t)
110110

111-
figure(1)
112-
clf()
113-
# Frame dimensions are [samples, chan, periods, frames]
114-
plot(vec(uFirstPeriod[:,1,:,:]))
115-
plot(vec(uCurrentPeriod[:,1,:,:]))
116-
plot(vec(uLastPeriod[:,1,:,:]))
117-
legend(("first period", "current period", "last period"))
118-
savefig("images/counterTrigger.png")
119-
111+
plot = lines(vec(uFirstPeriod[:,1,:,:]), label = "first period")
112+
lines!(plot.axis, vec(uCurrentPeriod[:,1,:,:]), label = "current period")
113+
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "last period")
114+
axislegend(plot.axis)
115+
save(joinpath(@__DIR__(), "images", "counterTrigger.png"), plot)
116+
plot
120117
#==
121118
0: enable
122119
1: trigger_arm

src/examples/julia/counterTriggerCluster.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33
using Statistics
44
using Base.Threads
55

@@ -108,15 +108,14 @@ counterTrigger_enabled!(rpc, false)
108108

109109
close(t)
110110

111-
figure(1)
112-
clf()
113111
chan = 3
114112
# Frame dimensions are [samples, chan, periods, frames]
115-
plot(vec(uFirstPeriod[:,chan,:,:]))
116-
plot(vec(uCurrentPeriod[:,chan,:,:]))
117-
plot(vec(uLastPeriod[:,chan,:,:]))
118-
legend(("first period", "current period", "last period"))
119-
savefig("images/counterTrigger.png")
113+
plot = lines(vec(uFirstPeriod[:,chan,:,:]), label = "first period")
114+
lines!(plot.axis, vec(uCurrentPeriod[:,chan,:,:]), label = "current period")
115+
lines!(plot.axis, vec(uLastPeriod[:,chan,:,:]), label = "last period")
116+
axislegend(plot.axis)
117+
save(joinpath(@__DIR__(), "images", "counterTriggerCluster.png"), plot)
118+
plot
120119

121120
#==
122121
0: enable

src/examples/julia/delay.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
# obtain the URL of the RedPitaya
55
include("config.jl")
@@ -44,10 +44,9 @@ uUncorrected = readSamples(rp, 0, 45, correct_filter_delay = false)
4444
masterTrigger!(rp, false)
4545
serverMode!(rp, CONFIGURATION)
4646

47-
figure(1)
48-
clf()
4947
# Sample dimensions are [chan, samples]
50-
plot(vec(uCorrected[1, :]))
51-
plot(vec(uUncorrected[1, :]))
52-
legend(("first period", "Corrected", "Uncorrected"))
53-
savefig("images/delay.png")
48+
plot = lines(vec(uCorrected[1, :]), label = "Corrected")
49+
lines!(plot.axis, vec(uUncorrected[1, :]), label = "Uncorrected")
50+
axislegend(plot.axis)
51+
save(joinpath(@__DIR__(), "images", "delay.png"), plot)
52+
plot

src/examples/julia/producerConsumer.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using RedPitayaDAQServer
22
using ThreadPools
3-
using PyPlot
3+
using CairoMakie
44

55
include("config.jl")
66

@@ -141,9 +141,7 @@ else
141141
# Wait for the consumer since otherwise Julia just terminates in non-interactive mode.
142142
wait(consumer)
143143

144-
figure(1)
145-
clf()
146144
# Frame dimensions are [samples, chan, periods, frames]
147-
plot(vec(buffer[:, 1, :, :]))
148-
savefig("images/producerConsumer.png")
145+
plot = lines(vec(buffer[:, 1, :, :]))
146+
save(joinpath(@__DIR__(), "images", "producerConsumer.png"), plot)
149147
end

src/examples/julia/ramping.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
# obtain the URL of the RedPitaya
55
include("config.jl")
@@ -37,9 +37,8 @@ masterTrigger!(rp, true)
3737

3838
uFirstPeriod = readFrames(rp, 0, 6)
3939

40-
41-
fr = currentFrame(rp)
42-
uCurrentPeriod = readFrames(rp, fr, 6)
40+
sleep(0.5)
41+
uCurrentPeriod = readFrames(rp, currentFrame(rp), 6)
4342

4443
# Start ramp down asynchronously
4544
# Note that we might not see the actual ramping in this example, see seqRamping.jl for that
@@ -52,11 +51,10 @@ masterTrigger!(rp, false)
5251
serverMode!(rp, CONFIGURATION)
5352
enableRamping!(rp, 1, false)
5453

55-
figure(1)
56-
clf()
5754
# Frame dimensions are [samples, chan, periods, frames]
58-
plot(vec(uCurrentPeriod[:,1,:,:]))
59-
plot(vec(uFirstPeriod[:,1,:,:]))
60-
plot(vec(uLastPeriod[:,1,:,:]))
61-
legend(("regular", "start", "end"))
62-
savefig("images/asyncRamping.png")
55+
plot = lines(vec(uCurrentPeriod[:,1,:,:]), label = "regular")
56+
lines!(plot.axis, vec(uFirstPeriod[:,1,:,:]), label = "start")
57+
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "end")
58+
axislegend(plot.axis)
59+
save(joinpath(@__DIR__(), "images", "asyncRamping.png"), plot)
60+
plot

src/examples/julia/seqRamping.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RedPitayaDAQServer
2-
using PyPlot
2+
using CairoMakie
33

44
# obtain the URL of the RedPitaya
55
include("config.jl")
@@ -46,13 +46,12 @@ masterTrigger!(rp, true)
4646
samples_per_step = (samples_per_period * periods_per_frame)/steps_per_frame
4747
uCurrentFrame = readFrames(rp, 0, 4)
4848

49-
fig = figure(1)
50-
clf()
51-
plot(vec(uCurrentFrame[:,1,:,1:4]))
52-
5349
masterTrigger!(rp, false)
5450
serverMode!(rp, CONFIGURATION)
5551
enableRamping!(rp, 1, false)
5652
clearSequence!(rp)
5753

58-
savefig("images/seqRamping.png")
54+
plot = lines(vec(uCurrentFrame[:,1,:,1:4]))
55+
56+
save(joinpath(@__DIR__(), "images", "seqRamping.png"), plot)
57+
plot

0 commit comments

Comments
 (0)