forked from KxSystems/embedPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatplotlibexample.q
More file actions
36 lines (27 loc) · 834 Bytes
/
matplotlibexample.q
File metadata and controls
36 lines (27 loc) · 834 Bytes
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
/ this example shows importing pyplot from matplotlib and exposing the methods in pyplot as q functions
/ it can be loaded in a q session with p.q loaded with
/ q)\l matplotlibexample.q
/ import matplotlib.pyplot and wrap it in a dictionary called plt
\l importmatplotlib.q
plt:.matplotlib.pyplot[]
/ now we create and display a simple plot
t:til[200]%100
pi:2*asin 1
s:1+sin 2*pi*t
/ because each of the plt functions returns a foreign we suppress output here
plt.plot[t;s];
plt.xlabel"time (s)";
plt.ylabel"voltage (mV)";
plt.title"A chart created using q data";
plt.grid 1b;
plt.show[];
\
This is equivalent to the python below
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.show()