Import modules and configure matplotlib output to notebook.
import re
import io
import os
import tempfile
import matplotlib.pyplot as plt
import matplotlib.image as mpim
import jonga
%matplotlib inline
Construct call tracer object with groups defined by the first part (i.e. before the first '.') of the fully qualified name of the function
ct = jonga.CallTracer(dstmodflt='^(re.|sre_)', grpflt=r'^[^\.]*')
Define graph construction option variables
size = '32,32'
fntsz = 12
fntfm = 'Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans'
Get path of temporary file for graph image
fd, pth = tempfile.mkstemp(suffix='.png')
os.close(fd)
Use context manager wrapper of call tracer to trace regex compile function and write a corresponding call graph image
with jonga.ContextCallTracer(ct, pth, size=size, fntsz=fntsz, fntfm=fntfm):
rc = re.compile(r'^[^\.]*.[^\.]*')
Read graph image and display it
img = mpim.imread(pth)
fig = plt.figure(figsize=(16, 16))
axim = plt.imshow(img)
ax = plt.axis('off')
plt.show()
Delete temporary image file
os.remove(pth)