图形轴校准在c ++中 [英] graph axis calibration in c++

查看:160
本文介绍了图形轴校准在c ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一个2D图形中的一些浮点数据,我需要将图形轴线校准成看起来整齐的小单元。显然这个单位根据数据的大小而变化。我试图找出一个很好的方法来将轴分成好看的数字。例如,如果我的数据从
-1.3345到+5.882运行,可能会以1.0或0.5为单位进行分割。如果我的数据从-100到800将坐标轴分为100或50的单位(我希望这很有意义),现在我将范围(最大值 - 最小值)除以某个固定整数,然后获得单位给我带有长尾数字的难看数字。有没有这样做的聪明方式?

解决方案

ACM算法463 提供了三个简单的函数,用于产生良好的轴比例尺,输出xminp,xmaxp和dist用于比例尺上的最小值和最大值以及比例尺上的刻度线之间的距离,给出<$ c $的请求包含数据点 xmin 和 xmax 的间隔:


  1. Scale1()给出了一个大约 n 间隔和 dist 是10倍1,2或5的整数次幂。
  2. Scale2()给出了一个精确的 n 区间的线性比例(xminp和xmaxp之间的差距往往大于<$ c产生的差距$ c $> Scale1())。
  3. Scale3()给出对数刻度。
  4. >

代码位于Fortran中,但解释并转换为其他代码非常简单r语言。有更复杂的函数可以提供更漂亮的尺度(例如 gnuplot 中的尺寸),但Scale1可能会用最少的代码为您完成这项工作。

(EDIT)

我在网上找到原始1973年的文章 here ,它提供了比上面链接的代码更多的解释。 / p>

I am plotting some float data in a 2D graph and I need to calibrate the axis of graph into small units that looks neat. Obviously this unit varies based on magnitude of the data. I am trying to find out a good way to divide the axis into nice looking number. for example if my data runs from -1.3345 to +5.882 may be divide in units of 1.0 or 0.5. if my data us from -100 to 800 divide the axes into units of 100 or 50. (I hope that makes sense) right now I am dividing the range (largest value - lowest value) by some fixed integer and getting the units but that gives me ugly looking number with long trailing digits. Is there any smart way of doing this?

解决方案

ACM Algorithm 463 provides three simple functions to produce good axis scales with outputs xminp, xmaxp and dist for the minimum and maximum values on the scale and the distance between tick marks on the scale, given a request for n intervals that include the data points xmin and xmax:

  1. Scale1() gives a linear scale with approximately n intervals and dist being an integer power of 10 times 1, 2 or 5.
  2. Scale2() gives a linear scale with exactly n intervals (the gap between xminp and xmaxp tends to be larger than the gap produced by Scale1()).
  3. Scale3() gives a logarithmic scale.

The code is in Fortran but it is very straightforward to interpret and convert into other languages. There are more complicated functions that give prettier scales (e.g. the ones in gnuplot), but Scale1 would likely do the job for you with minimal code.

(EDIT)

I found the text of the original 1973 paper online here, which provides more explanation than the code linked to above.

这篇关于图形轴校准在c ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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