-
Notifications
You must be signed in to change notification settings - Fork 2
/
plt_interactive_test.py
44 lines (31 loc) · 1.2 KB
/
plt_interactive_test.py
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
"""Matplotlib interactive test.
http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode
**Summary**
In interactive mode, pyplot functions automatically draw to the screen.
When plotting interactively, if using object method calls in addition to pyplot
functions, then call draw() whenever you want to refresh the plot.
Use non-interactive mode in scripts in which you want to generate one or more
figures and display them before ending or generating a new set of figures.
In that case, use show() to display the figure(s) and to block execution until
you have manually destroyed them.
"""
import matplotlib.pyplot as plt
import numpy as np
plt.ioff() # Do not need ion()
def test():
"""Test iteractive and non-interactive plotting.
Plots 1 and 3 show on screen and waits for user.
Plots 2 and 4 saved automatically to files.
"""
is_interactive = [True, False, True, False]
for i, ion in enumerate(is_interactive, 1):
a = np.random.rand(100, 100)
plt.clf()
plt.imshow(a)
plt.title('Plot {0}'.format(i))
plt.draw()
if ion:
plt.show()
else:
plt.savefig('test{0}.png'.format(i))
plt.close()