@@ -306,7 +306,8 @@ def add_brackets(xloc, yloc, xshift=0, color="r", label=None, options=None):
306306 value to subtract to xloc.
307307 """
308308 try :
309- import pylab as pl
309+ import matplotlib .pyplot as pl
310+ import numpy as np
310311 except ImportError as e :
311312 print ("matplotlib is needed for plotting." )
312313 print (e )
@@ -315,16 +316,17 @@ def add_brackets(xloc, yloc, xshift=0, color="r", label=None, options=None):
315316 vsize = (pl .ylim ()[1 ] - pl .ylim ()[0 ]) / height_ratio
316317 hsize = (pl .xlim ()[1 ] - pl .xlim ()[0 ]) / (3. * height_ratio )
317318
318- bracket_x = pl .asarray ([hsize , 0 , 0 , hsize ])
319- bracket_y = pl .asarray ([vsize , vsize , - vsize , - vsize ])
319+ bracket_x = np .asarray ([hsize , 0 , 0 , hsize ])
320+ bracket_y = np .asarray ([vsize , vsize , - vsize , - vsize ])
320321
321322 # Matplotlib workaround: labels starting with _ aren't displayed
322323 if label [0 ] == '_' :
323324 label = ' ' + label
324- if options .xlim is None or options .xlim [0 ] <= (xloc [0 ] - xshift ) <= options .xlim [1 ]:
325+ xlim = getattr (options , 'xlim' , None ) if options is not None else None
326+ if xlim is None or xlim [0 ] <= (xloc [0 ] - xshift ) <= xlim [1 ]:
325327 pl .plot (bracket_x + xloc [0 ] - xshift , bracket_y + yloc [0 ],
326328 "-" + color , linewidth = 2 , label = label )
327- if options . xlim is None or options . xlim [0 ] <= (xloc [1 ] - xshift ) <= options . xlim [1 ]:
329+ if xlim is None or xlim [0 ] <= (xloc [1 ] - xshift ) <= xlim [1 ]:
328330 pl .plot (- bracket_x + xloc [1 ] - xshift , bracket_y + yloc [1 ],
329331 "-" + color , linewidth = 2 )
330332
@@ -401,12 +403,12 @@ def read_mprofile_file(filename):
401403
402404def plot_file (filename , index = 0 , timestamps = True , children = True , options = None ):
403405 try :
404- import pylab as pl
406+ import matplotlib . pyplot as pl
405407 except ImportError as e :
406408 print ("matplotlib is needed for plotting." )
407409 print (e )
408410 sys .exit (1 )
409- import numpy as np # pylab requires numpy anyway
411+ import numpy as np # matplotlib requires numpy anyway
410412 mprofile = read_mprofile_file (filename )
411413
412414 if len (mprofile ['timestamp' ]) == 0 :
@@ -431,18 +433,19 @@ def plot_file(filename, index=0, timestamps=True, children=True, options=None):
431433
432434 mem = np .asarray (mem )
433435 t = np .asarray (t )
434- global_start = t [0 ]
435- t = t - global_start
436-
437- if options .xlim is not None :
438- cond = (t >= options .xlim [0 ]) & (t <= options .xlim [1 ])
439- mem , t = mem [cond ], t [cond ]
440-
441436 ind = t .argsort ()
442437 mem = mem [ind ]
443438 t = t [ind ]
444439
445440 # Plot curves
441+ global_start = float (t [0 ])
442+ t = t - global_start
443+
444+ if options is not None and getattr (options , 'xlim' , None ) is not None :
445+ # Filter points to the requested xlim window so the y-axis and peak
446+ # memory marker rescale to the visible range (PR #367).
447+ cond = (t >= options .xlim [0 ]) & (t <= options .xlim [1 ])
448+ mem , t = mem [cond ], t [cond ]
446449 max_mem = mem .max ()
447450 max_mem_ind = mem .argmax ()
448451
@@ -538,12 +541,12 @@ def plot_file(filename, index=0, timestamps=True, children=True, options=None):
538541
539542def flame_plotter (filename , index = 0 , timestamps = True , children = True , options = None ):
540543 try :
541- import pylab as pl
544+ import matplotlib . pyplot as pl
542545 except ImportError as e :
543546 print ("matplotlib is needed for plotting." )
544547 print (e )
545548 sys .exit (1 )
546- import numpy as np # pylab requires numpy anyway
549+ import numpy as np # matplotlib requires numpy anyway
547550 mprofile = read_mprofile_file (filename )
548551
549552 if len (mprofile ['timestamp' ]) == 0 :
@@ -798,7 +801,7 @@ def xlim_type(value):
798801 import matplotlib
799802 matplotlib .use (args .backend )
800803
801- import pylab as pl
804+ import matplotlib . pyplot as pl
802805 except ImportError as e :
803806 print ("matplotlib is needed for plotting." )
804807 print (e )
0 commit comments