算法"好的"在图上的网格线间隔 [英] Algorithm for "nice" grid line intervals on a graph

查看:170
本文介绍了算法"好的"在图上的网格线间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个相当聪明的算法来为图形(图)好网格线。

I need a reasonably smart algorithm to come up with "nice" grid lines for a graph (chart).

例如,假设一个条形图的10,30,72和60的值你知道吗:

For example, assume a bar chart with values of 10, 30, 72 and 60. You know:

最小值:10 最高值:72 范围:62

Min value: 10 Max value: 72 Range: 62

第一个问题是:你怎么开始?在这种情况下,0将是直观的值,但是这不会耽误其他数据集,所以我猜测:

The first question is: what do you start from? In this case, 0 would be the intuitive value but this won't hold up on other data sets so I'm guessing:

电网最小值应该是0或好的价值比范围内的数据的最小值低。可替代地,它可以被指定。

Grid min value should be either 0 or a "nice" value lower than the min value of the data in range. Alternatively, it can be specified.

电网最高值应该是一个好的价值高于该范围内的最大值。或者,也可以指定(例如,您可能想0到100,如果你显示百分比,而不管实际值)。

Grid max value should be a "nice" value above the max value in the range. Alternatively, it can be specified (eg you might want 0 to 100 if you're showing percentages, irrespective of the actual values).

的网格线(刻度)范围内的数字应该是指定或数字在一定范围内(如3-8),使得值好(即24号),你最大限度地利用的图表区域。在我们的例子中,80将是一个明智的最大,因为这将使用90%的图表高度(八十分之七十二),而100会造成更多的浪费空间。

The number of grid lines (ticks) in the range should be either specified or a number within a given range (eg 3-8) such that the values are "nice" (ie round numbers) and you maximise use of the chart area. In our example, 80 would be a sensible max as that would use 90% of the chart height (72/80) whereas 100 would create more wasted space.

任何人都知道一个好的算法,这一点?语言是无关紧要的,因为我会在我需要什么来实现它。

Anyone know of a good algorithm for this? Language is irrelevant as I'll implement it in what I need to.

推荐答案

CPAN提供了一个实现的此处(见源链接)

CPAN provides an implementation here (see source link)

另请参见 对勾标记算法图轴

See also Tickmark algorithm for a graph axis

仅供参考,您的样本数据:

FYI, with your sample data:

  • 枫:最小= 8,最大= 74,标签= 10,20,...,60,70,蜱= 10,12,14,...... 70,72
  • 在MATLAB:最小= 10,最大= 80,标签= 10,20 ,, ..,60,80

这篇关于算法"好的"在图上的网格线间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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