如何绘制在C直方图 [英] how to plot a histogram in c
问题描述
如何从2个数组绘制在C直方图?
how do I plot a histogram in c from 2 arrays?
推荐答案
约一点我不相信,重复我在评论中发现的问题思考实在是有求必应。所以我会说几句话。
Thinking about the problem a bit I'm not convinced that the "duplicate" I identified in the comments is really responsive. So I'll say a few words.
如果您已经在一个ASCII艺术的方式解决,那么你只有一个更多的决定,使:垂直或水平条。水平很简单:只是决定缩放,然后打印每个仓 bin_contents *比例
符号。在code-高尔夫链接确实是一个有用的模型的什么的做,甚至如果没有一个很好的例子的如何的写。
If you've settled on a ASCII art approach, then you have only one more decision to make: vertical or horizontal bars. Horizontal is easy: just decide on the scaling and then print bin_contents*scale
symbols for each bin. The code-golf link really is useful as a model of what to do, even if not a good example of how to write it.
然而,许多领域在直方图的presentation竖条的期望。这是一个有点困难,但考虑到伪code
However, many fields have an expectation of vertical bar in the presentation of histograms. That's a little harder, but consider the pseudocode
sacle = find_scale(input_array)
max_height = find_max(input_array) * scale
for (i=max_height; i>=0; i--)
if (some condition)
print_in_N_digits(round(i/scale)) // to label the scale
else
print_in_N_digits() // lines with no labels
print " |" // set up the vertical axis
for (j=first_bin to lat_bin)
if (input[j]*scale >= i)
print("#")
else
print(" ")
print_new_line
print_in_N_digits(0)
print(" +")
for (j=first_bin to last_bin)
print("-")
print_new_line
print_in_N_digits()
print(" 0")
for (j=first_bin to last_bin)
if (some other condition)
print_bin_label
这只是走在整个页面,使用上栏每仓,并在每个级别的打印或者,
或#
为每列。直方图印刷部分是真的很不容易。所有的复杂性来自管理轴线和标签
This just walks across the page, using on column per bin and at each level prints either " "
or "#"
for each column. The histogram printing part is really very easy. All the complexity arises from managing the axis and labels.
这篇关于如何绘制在C直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!