不同功能的样本数量不同 [英] Different number of samples for different functions

查看:81
本文介绍了不同功能的样本数量不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

plot x+3 , x**2+5*x+12 

是否可以将x+3设置为只有2个样本,而x**2+5*x+12设置为在同一图中有1000个样本?

Is it possible to set x+3 to have only 2 samples and x**2+5*x+12 to have say 1000 samples in the same plot?

推荐答案

可以完成,但不能立即使用.

It can be done, but not out-of-the-box.

第一个变体使用一个临时文件来保存一个采样率较低的函数,然后与高分辨率函数一起绘制出来:

The first variant uses a temporary file to save one function with a low sampling rate and plotting it later together with the high-resolution function:

set samples 2
set table 'tmp.dat'
plot x+3
unset table
set samples 1000
plot 'tmp.dat' w lp t 'x+3', x**2 + 5*x + 12

这有一个优势,您可以为这两个功能使用任何采样率.

This has the advantage, that you can use any sampling rates for both functions.

对于一个函数的2示例的特殊情况,它可以在没有外部文件的情况下完成,但是涉及很多技巧:

For you special case of 2 samples for one function, it can be done without an external file, but it involves quite some tricking:

set xrange [-10:10]
s = 1000
set samples s
f1(x) = x + 3

set style func linespoints
set style data linespoints
plot '+' using (x0 = (($0 == 0 || $0 == (s-1) )? $1 : x0), \
                ($0 < (s-2) ? 1/0 : x0)):(f1(x0)) t 'x+3',\
     x**2 + 5*x + 12

我在这里所做的是:

  1. 使用特殊文件名+在当前xrange中生成一组坐标.必须设置此项,否则无法自动缩放.
  2. 通过给它们除值1/0而跳过除第一个点和最后一个点之外的所有点不起作用,因为其余两个点未连接.
  3. 因此,我存储第一个x值(当$0column(0)等于0时),并在遇到第二个最后一点时使用它.对于最后一点,使用通常的值.
  1. Use the special filename + to generate a set of coordinates in the current xrange. This must be set, no autoscaling is possible.
  2. Skipping all points but the first and the last by giving them the value 1/0 doesn't work, because the two remaining points aren't connected.
  3. So I store the first x-value (when $0, or column(0) equals 0) and use it when I encountered the second last points. For the last points, the usual values are used.

这适用于您的2样本的特殊情况.

That works for your special case of 2 samples.

您必须牢记,第一个功能被视为数据,因此必须同时使用set style dataset style func(仅用于显示).

You must keep in mind, that the first function is treated as data, so you must use both set style data and set style func (just to show it).

4.6.4的结果是:

The result with 4.6.4 is:

这篇关于不同功能的样本数量不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆