如何在c中绘制直方图
如何在 c 中从 2 个数组绘制直方图?
how do I plot a histogram in c from 2 arrays?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 c 中从 2 个数组绘制直方图?
how do I plot a histogram in c from 2 arrays?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可以用这个字符(■)来表示图表中的计数。这是一个可以通过
考虑一些保存计数的随机
float_arr
和hist
数组来打印的字符。代码
输出
You could you this character(■) to represent the count in the graph. This is a character that can be printed by
Consider some random
float_arr
andhist
array that hold the count.Code
Output
对于侧面放置的直方图...
我建议对每个增量使用 printf("*") ,并使用 printf("\n") 开始输出新行。 (改变方向对读者来说是一种练习)。
For a histogram layed out on its side...
I suggest using printf("*") for each increment, and printf("\n") to start outputting a new row. (Changing the orientation is an excercise to the reader).
你可以使用 ascii art 来实现
You can use ascii art for that
稍微思考一下这个问题,我不相信我在评论中确定的“重复”确实有反应。那么我就说几句话吧。
如果您选择了 ASCII 艺术方法,那么您只需做出一个决定:垂直条还是水平条。水平很简单:只需决定缩放比例,然后为每个 bin 打印
bin_contents*scale
符号。代码高尔夫链接作为做什么的模型确实很有用,即使不是如何编写它的一个很好的例子。然而,许多领域都期望在直方图的呈现中使用垂直条。这有点困难,但考虑伪代码
这只是遍历页面,在每个容器的列上使用,并在每个级别为每个列打印
" "
或"#"
。直方图打印部分确实非常简单。所有的复杂性都源于管理轴和标签。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.
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.However, many fields have an expectation of vertical bar in the presentation of histograms. That's a little harder, but consider the pseudocode
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.