gpt4 book ai didi

ruby - 如何卡住 ruby​​-gnuplot 中的轴范围,并在卡住图的顶部绘制?

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:52 24 4
gpt4 key购买 nike

我想绘制一个通用数据集

plot.data << ::Gnuplot::DataSet.new([x, y]) do |ds|
ds.with = "lines linewidth 2"
ds.notitle
end

然后卡住绘图的自动 y 范围,以便在某个位置“x1”绘制一条垂直线,从该 y 范围的底部到顶部。我设置了一些变量并调用了绘图:

a = [x1, x1]
b = [0, y.sort.last * 1.1]

plot.data << ::Gnuplot::DataSet.new([a, b]) do |ds|
ds.with = "lines linewidth 2 lt 0 lc 3"
ds.notitle
end

其中 b 的值被选择为填充 y 轴范围。但是,当然,gnuplot 扩展了轴范围以适应数组 b 的大值。因此,我没有从上到下画一条线,我仍然有一条线向上延伸了大约 90%,但我的数据被压缩了一点。

最佳答案

您可以使用 set arrowgraph 坐标绘制一条横跨整个图形的垂直线。以sin_wave.rb例如,这里是一个例子:

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require "gnuplot"
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|

plot.xrange "[-10:10]"
plot.title "Sin Wave Example"
plot.ylabel "sin(x)"
plot.xlabel "x"

x1 = 2
plot.arrow "from first %f,graph 0 rto first 0,graph 1 nohead lw 2 lt 0 lc 3" % x1

plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
ds.with = "lines"
ds.linewidth = 4
end

end
sleep 10
end

结果

enter image description here

对于 firstgraph 以外的可用坐标系,请参见例如https://stackoverflow.com/a/23180595/2604213

关于ruby - 如何卡住 ruby​​-gnuplot 中的轴范围,并在卡住图的顶部绘制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23333718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com