-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_pyplot.cpp
More file actions
93 lines (82 loc) · 1.71 KB
/
test_pyplot.cpp
File metadata and controls
93 lines (82 loc) · 1.71 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "../utils/utils.hh"
#include "../utils/StatVector.hh"
#include "../utils/TimeStamp.hh"
#include "pyplot.hh"
#include <iostream>
#include <iomanip>
#include <cmath>
void test1(){
PyPlot plt("trig");
const int N = 400;
double x[N];
double y[N];
for(int i=0; i < N; i++){
x[i] = 6*PI*i/N;
y[i] = sin(x[i]);
}
plt.plot(x, y, N);
plt.linestyle("--");
plt.linewidth("3");
plt.linecolor("red");
for(int i=0; i < N/10; i++){
x[i] = 6*PI*i/(N/10);
y[i] = sin(x[i]);
}
plt.plot(x, y, N/10);
plt.linestyle("None");
plt.markertype("o");
plt.markersize("7");
plt.markercolor("black");
plt.axis(0, 15, -2, 2);
plt.title("sin(x) vs. x");
double xticks[6] = {0, 1.6, 1.6+3.2, 1.6+6.4, 1.6+9.6,
1.6+4*3.2};
double yticks[5] = {-0.75, -0.5, 0, 0.5, 0.75};
plt.xticks(xticks, 6);
plt.yticks(yticks, 5);
//plt.ticksize("20");
const char *cmd =
"plt.xlabel('OK')"
"\n";
plt.pycmd(cmd);
plt.show();
plt.savescript();
}
void makeplot(double *x, double *y, int n, const char *name){
PyPlot plt(name, PLTOFF);
plt.plot(x, y, n);
plt.show();
}
/*
* Makes n plots and times them.
* Plot number k is called sink.
* It is a plot of sin(kx) vs. x
*/
void timeplot(int n){
double x[n*10];
double y[n*10];
StatVector stats(n);
TimeStamp clk;
for(int i=1; i <= n; i++){
printf("\r%d", i);
fflush(stdout);
char name[30];
sprintf(name, "sin%d", i);
for(int j=0; j < n*10; j++){
x[j] = 2*PI*i*j/(n*10.0);
y[j] = sin(x[j]*i);
}
clk.tic();
makeplot(x, y, 10*n, name);
double cycles = clk.toc();
stats.insert(cycles);
}
char banner[200];
sprintf(banner, "cycle stats for %d plots", n);
stats.print(banner);
system("rm FIGS/sin*.pdf");
}
int main(){
test1();
//timeplot(100);
}