1 | #include <iostream> |
---|
2 | #include "RpScatter.h" |
---|
3 | |
---|
4 | int main() |
---|
5 | { |
---|
6 | // plot object |
---|
7 | Rappture::Scatter *p1 = NULL; |
---|
8 | |
---|
9 | // data arrays |
---|
10 | double x[] = {1,2,3,4,5,6,7,8,9,10}; |
---|
11 | double y[] = {1,4,9,16,25,36,49,64,81,100}; |
---|
12 | double z[] = {1,8,27,64,125,216,343,512,729,1000}; |
---|
13 | |
---|
14 | // number of points in x, y, z arrays |
---|
15 | size_t nPts = 10; |
---|
16 | |
---|
17 | // line format: green line, dotted line style, circle marker |
---|
18 | const char *fmt = "g:o"; |
---|
19 | |
---|
20 | p1 = new Rappture::Scatter(); |
---|
21 | |
---|
22 | // add 3 curves to the plot, with format and curve name |
---|
23 | // x vs y, x vs z, x vs x |
---|
24 | // curve name can be used to retrieve curve pointer later |
---|
25 | // blank format means autogenerate the format |
---|
26 | p1->add(nPts,x,y,fmt,"curve1"); |
---|
27 | p1->add(nPts,x,z,"b-*","curve2"); |
---|
28 | p1->add(nPts,x,x,"","curve3"); |
---|
29 | |
---|
30 | p1->propstr("xlabel","Voltage"); |
---|
31 | p1->propstr("xdesc","Voltage along the Gate"); |
---|
32 | p1->propstr("xunits","Volt"); |
---|
33 | p1->propstr("xscale","linear"); |
---|
34 | p1->propstr("ylabel","Current"); |
---|
35 | p1->propstr("ydesc","Current along the Drain"); |
---|
36 | p1->propstr("yunits","Amp"); |
---|
37 | p1->propstr("yscale","log"); |
---|
38 | |
---|
39 | // number of curves in this plot |
---|
40 | size_t curveCnt = p1->count(); |
---|
41 | std::printf("curveCnt = %zu\n",curveCnt); |
---|
42 | |
---|
43 | size_t indent = 0; |
---|
44 | size_t tabstop = 4; |
---|
45 | std::printf("xml: %s\n",p1->xml(indent,tabstop)); |
---|
46 | |
---|
47 | /* |
---|
48 | // retrieve curve from curve name |
---|
49 | // may want to add curve to another plot |
---|
50 | // or just read through the values |
---|
51 | Rappture::Curve *c = p1->curve("curve1"); |
---|
52 | |
---|
53 | const double *ax = NULL; |
---|
54 | const double *ay = NULL; |
---|
55 | size_t xlen = 0; |
---|
56 | size_t ylen = 0; |
---|
57 | |
---|
58 | xlen = c->data(Rappture::Curve::xaxis,&ax); |
---|
59 | ylen = c->data(Rappture::Curve::yaxis,&ay); |
---|
60 | |
---|
61 | std::printf("xlen = %zu\nylen = %zu\n",xlen,ylen); |
---|
62 | std::printf("fmt = %s\n",c->propstr(Rappture::Curve::format,NULL)); |
---|
63 | |
---|
64 | if ( (ax != NULL) |
---|
65 | && (ay != NULL)) { |
---|
66 | for (size_t i = 0; (i < xlen) && (i < ylen); i++) { |
---|
67 | std::printf("x = %g y = %g\n",ax[i],ay[i]); |
---|
68 | } |
---|
69 | } |
---|
70 | */ |
---|
71 | |
---|
72 | delete p1; |
---|
73 | |
---|
74 | return 0; |
---|
75 | } |
---|