This notebook shows how to use zmpl to use matplotlib plotting functionality out of process. This can be useful when you need to interactively visualize data for example when debugging code within some IDE that does not support using matplotlib from the Debug REPL, e.g. PTVS.
In [2]:
import numpy as np
import zmpl
# change this if you want to start the server manually (for debugging)
# zmpl.options['server_auto_start'] = False
from zmpl import pyplot as zplt
print('auto_draw is {}'.format('ON' if zplt.auto_draw() else 'OFF'))
We start by a simple hello world. This code plots the numbers $[0, 10)$ and adds a title Hello zmpl. Notice you don't need to call zmpl.show to see the results.
In [3]:
zplt.clf()
zplt.plot(range(10))
zplt.title('Hello zmpl!')
Out[3]:
Now we can acheive some interactivity very simply without using the ion and pause functions. This code will generate a random image of 100 by 100 pixels and displays them using imshow.
In [5]:
# disable auto draw
zplt.auto_draw(False)
for i in range(10):
zplt.clf()
data = np.random.random((100, 100, 3))
zplt.hold(True)
zplt.imshow(data)
zplt.plot(range(25, 76), range(25, 76), 'k-', linewidth=2.0)
zplt.axis('square')
zplt.axis('tight')
zplt.hold(False)
zpl
We can also use some module objects like figure and axes
In [8]:
# enable auto draw
zplt.auto_draw(True)
f1 = zplt.figure(1)
ax1 = f1.add_subplot(111)
ax1.plot(range(10), 'g-')
zplt.title('Figure 1')
f2 = zplt.figure(2)
ax2 = f2.add_subplot(111)
ax2.plot(range(20), 'r-')
zplt.title('Figure 2')
Out[8]:
The objects are special proxy types that are created on the fly by our simple RPC system.
In [16]:
print(type(f1))
print(dir(f1)[:20])
In [17]:
print(type(ax1))
print(dir(ax1)[:20])
In [ ]: