MCPcopy Index your code
hub / github.com/pythonprofilers/memory_profiler / add_brackets

Function add_brackets

mprof.py:293–337  ·  view source on GitHub ↗

Add two brackets on the memory line plot. This function uses the current figure. Parameters ========== xloc: tuple with 2 values brackets location (on horizontal axis). yloc: tuple with 2 values brackets location (on vertical axis) xshift: float valu

(xloc, yloc, xshift=0, color="r", label=None, options=None)

Source from the content-addressed store, hash-verified

291
292
293def add_brackets(xloc, yloc, xshift=0, color="r", label=None, options=None):
294 """Add two brackets on the memory line plot.
295
296 This function uses the current figure.
297
298 Parameters
299 ==========
300 xloc: tuple with 2 values
301 brackets location (on horizontal axis).
302 yloc: tuple with 2 values
303 brackets location (on vertical axis)
304 xshift: float
305 value to subtract to xloc.
306 """
307 try:
308 import pylab as pl
309 except ImportError as e:
310 print("matplotlib is needed for plotting.")
311 print(e)
312 sys.exit(1)
313 height_ratio = 20.
314 vsize = (pl.ylim()[1] - pl.ylim()[0]) / height_ratio
315 hsize = (pl.xlim()[1] - pl.xlim()[0]) / (3. * height_ratio)
316
317 bracket_x = pl.asarray([hsize, 0, 0, hsize])
318 bracket_y = pl.asarray([vsize, vsize, -vsize, -vsize])
319
320 # Matplotlib workaround: labels starting with _ aren't displayed
321 if label[0] == '_':
322 label = ' ' + label
323 if options.xlim is None or options.xlim[0] <= (xloc[0] - xshift) <= options.xlim[1]:
324 pl.plot(bracket_x + xloc[0] - xshift, bracket_y + yloc[0],
325 "-" + color, linewidth=2, label=label)
326 if options.xlim is None or options.xlim[0] <= (xloc[1] - xshift) <= options.xlim[1]:
327 pl.plot(-bracket_x + xloc[1] - xshift, bracket_y + yloc[1],
328 "-" + color, linewidth=2)
329
330 # TODO: use matplotlib.patches.Polygon to draw a colored background for
331 # each function.
332
333 # with maplotlib 1.2, use matplotlib.path.Path to create proper markers
334 # see http://matplotlib.org/examples/pylab_examples/marker_path.html
335 # This works with matplotlib 0.99.1
336 ## pl.plot(xloc[0], yloc[0], "<"+color, markersize=7, label=label)
337 ## pl.plot(xloc[1], yloc[1], ">"+color, markersize=7)
338
339
340def read_mprofile_file(filename):

Callers 1

plot_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected