[英]Plotting Graphs in c
i am beginner in c programming, i am currently using gedit of ubuntu 10.04 to write c prog, i want to plot a graph, but i am able to do it, can any one tell me hw it can be done or else is there any way to extract the data from the output to spreadsheet where i can plot the req, graph??我是 c 编程的初学者,我目前正在使用 ubuntu 10.04 的 gedit 来编写 c prog,我想绘制一个图形,但我能够做到,谁能告诉我它可以做到,否则有什么将数据从输出中提取到电子表格的方法,我可以在其中绘制请求、图表? I appreciate your help..n thanx!!!
我感谢你的帮助..nthanx!!!
Medsphere 有一些非常棒的GTK# 小部件用于绘图(除其他外),但是您需要更清楚地了解您的输入/输出要求才能获得更具体的帮助。
You could you this character(■) to represent the count in the graph.您可以使用这个字符(■) 来表示图中的计数。 This is a character that can be printed by
这是一个可以打印的字符
printf("%c", (char)254u);
Consider some random float_arr
and hist
array that hold the count.考虑一些保存计数的随机
float_arr
和hist
数组。
Code代码
// Function generating random data
for (i = 0; i < n; i++){
float random = ((float)rand() / (float)(RAND_MAX));
float_arr[i] = random;
printf("%f ", random);
}
//Dividing float data into bins
for (i = 0; i < n; i++){
for (j = 1; j <= bins; j++){
float bin_max = (float)j / (float)bins;
if (float_arr[i] <= bin_max){
hist[j]++;
break;
}
}
}
// Plotting histogram
printf("\n\nHistogram of Float data\n");
for (i = 1; i <= bins; i++)
{
count = hist[i];
printf("0.%d |", i - 1);
for (j = 0; j < count; j++)
{
printf("%c", (char)254u);
}
printf("\n");
}
Output输出
Histogram of Float data
0.0 |■■■■■■■■■■■■■■■■■■■■■■
0.1 |■■■■■■■■■■■■■■■■
0.2 |■■■■■
0.3 |■■■■■■■■■■■■■■
0.4 |■■■■■■■■
0.5 |■■■■■■■■■■■■■■■■
0.6 |■■■■■■■■■■
0.7 |■■■■■■■
0.8 |■■■■■■■■■■■■■■■
0.9 |■■■■■■■
Your problem is the same that I have.你的问题和我一样。 To do this there are some libraries written to facilitate the work that is more or less this:
为此,编写了一些库来促进或多或少这样的工作:
In c/c++ there are some of these libraries are:在 c/c++ 中有一些这样的库是:
Another way to make a plot is to generate your data in your c code and then plot it with an other program.绘制绘图的另一种方法是在您的 c 代码中生成您的数据,然后使用其他程序绘制它。 It is possible to run gnuplot and pass your data trough a pipe.
可以运行 gnuplot 并通过管道传递数据。 But you must use fork and pipes.
但是你必须使用叉子和管道。
Gnuplot (http://www.gnuplot.info/) is a pretty capable and free tool for graphing data. Gnuplot (http://www.gnuplot.info/) 是一款功能强大且免费的数据绘图工具。 Your question is not clear as to whether you want to plot data programmatically though.
您的问题不清楚是否要以编程方式绘制数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.