forked from bytebrew/slope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
47 lines (39 loc) · 1.17 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "build/config.h"
#if SLOPE_GTK
# include <slope/gtk.h>
# include <slope/view.h>
#else
# include <slope/slope.h>
#endif /* SLOPE_GTK */
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define N 100
int main (int argc, char *argv[])
{
/* generate some item */
const double step = 2.0*M_PI/N;
double x[N], y1[N], y2[N];
int k;
for (k=0; k<N; k++) {
x[k] = k*step;
y1[k] = sin(x[k]);
y2[k] = y1[k] + 0.2*((double)rand())/RAND_MAX - 0.1;
}
/* this is all you need to know to crete a chart */
slope_figure_t *chart = slope_chart_create("Sine and Random Noise", "phase", "amplitude");
slope_chart_add_plot(chart, x, y2, N, "Noisy experiment data", "l+");
slope_chart_add_plot(chart, x, y1, N, "Sine approximation", "r-");
#if SLOPE_GTK
/* put the scene in a gtk widget */
gtk_init(&argc,&argv);
GtkWidget *window = slope_create_window(chart, "Data and Model");
gtk_widget_show_all(window);
gtk_main();
#else
/* save the chart in a png figure */
slope_figure_write_to_png(chart, "figure.png", 500, 350);
#endif /* SLOPE_GTK */
slope_chart_destroy(chart);
return 0;
}