MCPcopy
hub / github.com/rueckstiess/mtools / plot

Method plot

mtools/mplotqueries/mplotqueries.py:591–702  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

589 plt.gcf().canvas.draw()
590
591 def plot(self):
592 # check if there is anything to plot
593 if len(self.plot_instances) == 0:
594 raise SystemExit('no data to plot.')
595
596 if self.args['output_file'] is not None:
597 # --output-file means don't depend on X,
598 # so switch to a pure-image backend before doing any plotting.
599 plt.switch_backend('agg')
600
601 self.artists = []
602 plt.figure(figsize=(12, 8), dpi=100, facecolor='w', edgecolor='w')
603 axis = plt.subplot(111)
604
605 # set xlim from min to max of logfile ranges
606 xlim_min = min([pi.date_range[0] for pi in self.plot_instances])
607 xlim_max = max([pi.date_range[1] for pi in self.plot_instances])
608
609 if xlim_max < xlim_min:
610 raise SystemExit('no data to plot.')
611
612 xlabel = 'time'
613 ylabel = ''
614
615 # use timezone of first log file (may not always be what user wants
616 # but must make a choice)
617 tz = self.logfiles[0].timezone
618 # tzformat='%b %d\n%H:%M:%S' if tz == tzutc() else '%b %d\n%H:%M:%S%z'
619
620 locator = AutoDateLocator(tz=tz, minticks=5, maxticks=10)
621 formatter = AutoDateFormatter(locator, tz=tz)
622
623 formatter.scaled = {
624 365.0: '%Y',
625 30.: '%b %Y',
626 1.0: '%b %d %Y',
627 1. / 24.: '%b %d %Y\n%H:%M:%S',
628 1. / (24. * 60.): '%b %d %Y\n%H:%M:%S',
629 }
630
631 # add timezone to format if not UTC
632 if tz != tzutc():
633 formatter.scaled[1. / 24.] = '%b %d %Y\n%H:%M:%S%z'
634 formatter.scaled[1. / (24. * 60.)] = '%b %d %Y\n%H:%M:%S%z'
635
636 for i, plot_inst in enumerate(sorted(self.plot_instances,
637 key=lambda pi: pi.sort_order)):
638 self.artists.extend(plot_inst.plot(axis, i,
639 len(self.plot_instances),
640 (xlim_min, xlim_max)))
641 if hasattr(plot_inst, 'xlabel'):
642 xlabel = plot_inst.xlabel
643 if hasattr(plot_inst, 'ylabel'):
644 ylabel = plot_inst.ylabel
645 if self.args['output_file'] is None:
646 self.print_shortcuts(scatter=isinstance(self.plot_instance,
647 plottypes.ScatterPlotType))
648

Callers 1

runMethod · 0.95

Calls 1

print_shortcutsMethod · 0.95

Tested by

no test coverage detected