【问题标题】:How can one freeze the axis range in ruby-gnuplot, and overplot on top of the frozen plot?如何冻结 ruby​​-gnuplot 中的轴范围,并在冻结图的顶部绘制?
【发布时间】:2014-04-28 06:11:07
【问题描述】:

我想绘制一个通用数据集

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

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

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%,但我的数据被压扁了一点。

【问题讨论】:

  • 如果它只是关于绘制一条跨越整个图形的垂直线,请在发出 plot 命令之前使用set arrow from first x1, graph 0 rto 0, graph 1 nohead lw 2 lt 0 lc 3(不过,我不知道如何将其包含到 ruby​​-gnuplot 中)。如果您可以包含一个完整的、可运行的小型示例脚本,而不仅仅是一个 sn-p,那就太好了。

标签: ruby gnuplot


【解决方案1】:

您可以使用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

结果

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 2014-03-30
    • 2017-07-16
    • 2017-08-19
    相关资源
    最近更新 更多