gnuplot:范围内的最大值和最小值 [英] gnuplot: max and min values in a range
问题描述
我正在绘制一些具有不同X范围的数据,我想根据当前X范围内数据的最大值和最小值更改yrange.当我使用GPVAL_Y_MAX和GPVAL_Y_MIN时,这些值对应于整个数据的最大值和最小值,而不仅仅是范围内的数据.
I'm plotting some data with a different X range and I would like to change yrange according to the maximum and minimum value of the data in the current X range. When I use GPVAL_Y_MAX and GPVAL_Y_MIN, these values correspond to the maximum and minimum of the whole data, not just the data in the range.
例如,我有以下数据:
1 3
2 5
3 8
4 20
5 30
我使用以下脚本:
plot 'data.txt' u 1:2;
set xrange [1:3];
replot
set xrange [1:5];
replot
在第一个情节中,我想在[3:8]中设置yrange,但是在第二个情节中,yrange应当为[3:30].如果我使用类似的东西
In the first plot I would like to set yrange in [3:8], but in the second plot the yrange sholud be [3:30]. If I use something like
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX]
GPVAL_Y_MIN和GPVAL_Y_MAX具有相同的值,而与xrange无关.
GPVAL_Y_MIN and GPVAL_Y_MAX have the same value independently of the xrange.
有解决方案吗?
推荐答案
所需的变量是GPVAL_DATA_Y_MIN
和GPVAL_DATA_Y_MAX
,它们是在特定范围内绘制的数据的y-min/max. GPVAL_Y_MIN
和GPVAL_Y_MAX
通常不太有用,因为它们告诉您绘图边框的边缘在哪里(通常,这些值超出了GPVAL_DATA...
变量的范围,因为gnuplot在数据和图的边缘).
The variables you want are GPVAL_DATA_Y_MIN
and GPVAL_DATA_Y_MAX
, which are the y-min/max of the data plotted in a certain range. GPVAL_Y_MIN
and GPVAL_Y_MAX
are a little less useful generally because they tell you where the edges of the plot border are (in general these values extend a little beyond the GPVAL_DATA...
variables because gnuplot leaves a little space between the data and the edge of the plot).
要利用这些变量,必须对plot命令使用范围说明符:
To take advantage of these variables you have to use the range specifiers to the plot command:
plot [1:3] 'data.txt'
set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
...
顺便说一句,除非您想提醒自己要绘制的列,否则u 1:2
规范是多余的,因为将前两列分别绘制为x和y是gnuplot的默认设置.如果您不想重新绘制到相同的输出端子(在像eps这样的某些端子中没有帮助,在该端子上重新绘制将以相同的图形绘制第二页),请使用以下命令序列:
By the way, the u 1:2
specification is redundant unless you want to remind yourself of which columns you are plotting, since plotting the first two columns as x and y is the gnuplot default. If you don't want to replot to the same output terminal (which is not helpful in some terminals like eps where replotting makes a second page with the same plot), use this command sequence:
set terminal unknown
plot [1:3] 'data.txt'
set terminal <actual output terminal here>
set output 'output.trm'
plot [1:3][GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX] 'data.txt'
请再次注意使用范围说明符,这一次指定了y范围.这比用set yrange
指定要紧凑一些,但是需要更长的代码行.
Note the use of the range specifier again, this time with a y range specified. This is a little more compact than specifying with set yrange
, but makes for a longer line of code.
如果您具有gnuplot 4.6.0或更高版本,则可以利用stats
命令来避免重新配置. stats
命令创建了一堆方便的变量
If you have gnuplot 4.6.0 or higher, you can take advantage of the stats
command to avoid replotting. The stats
command creates a bunch of handy variables
stats [1:3] 'data.txt'
plot [1:3][stats_min_y:stats_max_y] 'data.txt'
一个稍微不同的命令,
stats [1:3] 'data.txt'
plot [stats_min_x:stats_max_x][stats_min_y:stats_max_y] 'data.txt'
将基于实际数据所在的位置在x方向上填充图.例如,如果您的数据点位于{(1.1,3),(2,4),(2.9,5)},则x范围将设置为[1.1:2.9].
Would fill the plot in the x direction based on where the actual data lie. For instance if you had data points at {(1.1, 3), (2, 4), (2.9,5)}, the x range would be set to [1.1:2.9].
这篇关于gnuplot:范围内的最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!