Coverage for mtools.mplotqueries.plottypes.scatter_type : 37%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
except ImportError: instructions how to install matplotlib or try mlogvis instead, which is a simplified version of mplotqueries \ that visualizes the logfile in a web browser.")
BasePlotType.__init__(self, args, unknown_args)
self.logscale = args['logscale']
# parse arguments further to get --yaxis argument argparser = argparse.ArgumentParser("mplotqueries --type scatter") argparser.add_argument('--yaxis', '-y', action='store', metavar='FIELD', default='duration') args = vars(argparser.parse_args(unknown_args))
if args['yaxis'] == 'duration': self.ylabel = 'duration in ms' else:
self.durlines = []
""" return True if the log line has the nominated yaxis field. """ return (getattr(logevent, self.field) != None)
# create x-coordinates for all log lines in this group x = date2num( [ logevent.datetime for logevent in self.groups[group] ] )
color, marker = self.color_map(group)
# duration plots require y coordinate and use plot_date y = [ getattr(logevent, self.field) for logevent in self.groups[group] ]
if self.logscale: axis.semilogy()
artist = axis.plot_date(x, y, color=color, markeredgecolor='k', marker=marker, alpha=0.7, \ markersize=7, picker=5, label=group)[0] # add meta-data for picking artist._mt_plot_type = self artist._mt_group = group
return artist
""" this is called if an element of this plottype was clicked. Implement in sub class. """ group = event.artist._mt_group
for i in indices:
else: # toggle durline logevent = self.groups[group][first]
try: # remove triangle for this event idx = map(itemgetter(0), self.durlines).index(logevent) _, poly = self.durlines[idx] poly.remove() plt.gcf().canvas.draw() del self.durlines[idx]
except ValueError: # construct triangle and add to list of durlines
if self.args['optime_start']: pts = [ [date2num(logevent.datetime), 0], [date2num(logevent.datetime), logevent.duration], [date2num(logevent.datetime + timedelta(milliseconds=logevent.duration)), 0] ] else: pts = [ [date2num(logevent.datetime), 0], [date2num(logevent.datetime), logevent.duration], [date2num(logevent.datetime - timedelta(milliseconds=logevent.duration)), 0] ]
poly = Polygon(pts, closed=True, alpha=0.2, linewidth=0, facecolor=event.artist.get_markerfacecolor(), edgecolor=None, zorder=-10000)
ax = plt.gca() ax.add_patch(poly) plt.gcf().canvas.draw()
self.durlines.append( (logevent, poly) )
ScatterPlotType.__init__(self, args, unknown_args) self.args['optime_start'] = True
# create x-coordinates for all log lines in this group x_start = date2num( [ logevent.datetime for logevent in self.groups[group] ] )
# duration plots require y coordinate and use plot_date y = [ getattr(logevent, 'duration') for logevent in self.groups[group] ]
if self.logscale: axis.semilogy()
# artist = axis.plot_date(x, y, color=color, markeredgecolor='k', marker=marker, alpha=0.7, \ # markersize=7, picker=5, label=group)[0]
artists = [] labels = set()
artist = axis.plot_date([xs, xe], [0, ye], '-', color=color, alpha=0.7, linewidth=2, markersize=7, picker=5, label=None if group in labels else group)[0]
labels.add(group)
# add meta-data for picking artist._mt_plot_type = self artist._mt_group = group artist._mt_line_id = i artists.append(artist)
return artists
group = event.artist._mt_group line_id = event.artist._mt_line_id print self.groups[group][line_id].line_str
# Only call baseplot type constructor, we don't need argparser BasePlotType.__init__(self, args, unknown_args)
self.ylabel = 'nscanned / n ratio'
""" return True if the log line has a duration. """ return getattr(logevent, 'nscanned') and getattr(logevent, 'nreturned')
# create x-coordinates for all log lines in this group x = date2num( [ logevent.datetime for logevent in self.groups[group] ] )
color, marker = self.color_map(group)
# duration plots require y coordinate and use plot_date nreturned = float(logevent.nreturned) if nreturned == 0.0: nreturned = 1.0
y = [ getattr(logevent, 'nscanned') / nreturned for logevent in self.groups[group] ] artist = axis.plot_date(x, y, color=color, marker=marker, alpha=0.5, \ markersize=7, picker=5, label=group)[0] # add meta-data for picking artist._mt_plot_type = self artist._mt_group = group
return artist
|