本文介绍了如何在gnuplot中控制Xtics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我想控制xtics的范围和数量.我使用gnuplot绘制数据文件,其中水平轴通常是时间(t),其取值范围为[0,t_max].好的,现在让我们假设以下情形:

As the title says, I want to control the range and the amount of xtics. I use gnuplot for plotting data files in which the horizontal axes is usually time (t) taking values in the interval [0, t_max]. OK, now let's suppose the following scenario:

时间的最大值是4086,并且此特定值事先未知.但是,可以使用

The maximum value of time is 4086 and this particular value is not known beforehand. However, it can be found using

stats "data.out" u 1
set xrange [0:STATS_max]

我的问题是如何将t的最大值四舍五入到最接近的百位数(在这种情况下为4100)?另外,是否有一种方法可以告诉gnuplot在水平轴上仅打印5个刻度,而不管其范围是什么(将最大值四舍五入到最接近的百位,或者十进制将始终除以5)?

My question is how can I round up the maximum value of t to the closest hundred (4100 in this case)? Also, is there a way to tell gnuplot to print only 5 ticks at the horizontal axes regardless of its range (rounding up the maximum value to the closest hundred, or decade it will always be divided by 5)?

非常感谢!

推荐答案

要舍入到最接近的百位数,只需使用ceil函数:

To round up to the closest hundred, just use the ceil function:

set xrange[0: 100*ceil(STATS_max/100.0)]

关于xtics,您只能设置tic的开始,增量,结束和明确的tic位置,但不能设置刻度的数量.但是,由于您手动设置了xrange,因此可以使用以下信息来计算tic频率:

Regarding the xtics, you can only set the start, increment, end, and explicit tic position of the tics, but not the number of ticks. But since you set the xrange manually, you can use this information to calculate the tic frequency:

x_lim = 100*ceil(STATS_max/100.0)
set xrange[0: x_lim]
set xtics x_lim/4.0

这篇关于如何在gnuplot中控制Xtics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:30