Last active
August 29, 2015 14:21
-
-
Save ievgrafov/7563d7ac7adb0db1f18c to your computer and use it in GitHub Desktop.
stateful example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x0 = (0..500).map{ |xx| xx/1000.0 } | |
y0 = x0.map{ |xx| Math.exp(-xx) } | |
x1 = (500..1000).map{ |xx| xx/1000.0 } | |
y1 = x1.map{ |xx| Math.exp(-xx) } | |
# create new datablock | |
datablock = Datablock.new([x0, y0]) | |
# now data will be sent to gnuplot and new datablock in terminal created | |
# everything is good, we still may have stateless objects | |
plot = Plot.new([datablock, with: 'lines', title: 'Exp (points)'], term: ['qt', persist: true]) | |
plot.plot # (1) | |
datablock.update!([x1, y1]) | |
plot.plot # plots updated data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x0 = (0..500).map{ |xx| xx/1000.0 } | |
y0 = x0.map{ |xx| Math.exp(-xx) } | |
x1 = (500..1000).map{ |xx| xx/1000.0 } | |
y1 = x1.map{ |xx| Math.exp(-xx) } | |
# create new datablock | |
datablock = Datablock.new([x0, y0]) | |
# now data will be sent to gnuplot and new datablock in terminal created | |
# everything is good, we still may have stateless objects | |
plot = Plot.new([datablock, with: 'lines', title: 'Exp (points)'], term: ['qt', persist: true]) | |
plot.plot # (1) | |
updated_datablock = datablock.update([x1, y1]) | |
updated_plot = plot.update_datablock(datablock, updated_datablock) | |
plot.plot # no problem, result is the same as in (1) | |
updated_plot.plot # plots updated data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x0 = (0..500).map{ |xx| xx/1000.0 } | |
y0 = x0.map{ |xx| Math.exp(-xx) } | |
x1 = (500..1000).map{ |xx| xx/1000.0 } | |
y1 = x1.map{ |xx| Math.exp(-xx) } | |
# create new datablock | |
datablock = Datablock.new([x0, y0]) | |
# now data will be sent to gnuplot and new datablock in terminal created | |
# everything is good, we still may have stateless objects | |
plot = Plot.new([datablock, with: 'lines', title: 'Exp (points)'], term: ['qt', persist: true]) | |
plot.plot # (1) | |
datablock.update([x1, y1]) | |
plot.plot # now we have a problem: image plotted in (1) isn't the same as this one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment