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

Method plot

mtools/mplotqueries/plottypes/histogram_type.py:78–149  ·  view source on GitHub ↗

Plot the histogram as a whole over all groups. Do not plot as individual groups like other plot types.

(self, axis, ith_plot, total_plots, limits)

Source from the content-addressed store, hash-verified

76 raise NotImplementedError("Not implemented for histogram plots.")
77
78 def plot(self, axis, ith_plot, total_plots, limits):
79 """
80 Plot the histogram as a whole over all groups.
81
82 Do not plot as individual groups like other plot types.
83 """
84 print(self.plot_type_str.upper() + " plot")
85 print("%5s %9s %s" % ("id", " #points", "group"))
86
87 for idx, group in enumerate(self.groups):
88 print("%5s %9s %s" % (idx + 1, len(self.groups[group]), group))
89
90 print('')
91
92 datasets = []
93 colors = []
94 minx = np.inf
95 maxx = -np.inf
96
97 for idx, group in enumerate(self.groups):
98 x = date2num([logevent.datetime
99 for logevent in self.groups[group]])
100 minx = min(minx, min(x))
101 maxx = max(maxx, max(x))
102 datasets.append(x)
103 color, marker = self.color_map(group)
104 colors.append(color)
105
106 if total_plots > 1:
107 # if more than one plot, move histogram to twin axis on the right
108 twin_axis = axis.twinx()
109 twin_axis.set_ylabel(self.ylabel)
110 axis.set_zorder(twin_axis.get_zorder() + 1) # put ax ahead of ax2
111 axis.patch.set_visible(False) # hide the 'canvas'
112 axis = twin_axis
113
114 n_bins = max(1, int((maxx - minx) * 24. * 60. * 60. / self.bucketsize))
115 if n_bins > 1000:
116 # warning for too many buckets
117 print("warning: %i buckets, will take a while to render. "
118 "consider increasing --bucketsize." % n_bins)
119
120 n, bins, artists = axis.hist(datasets, bins=n_bins, align='mid',
121 log=self.logscale,
122 histtype="barstacked"
123 if self.barstacked else "bar",
124 color=colors, edgecolor="none",
125 linewidth=0, alpha=0.8, picker=True,
126 label=map(str, self.groups.keys()))
127
128 # scale current y-axis to match min and max values
129 axis.set_ylim(np.min(n), np.max(n))
130
131 # add meta-data for picking
132 if len(self.groups) > 1:
133 for g, group in enumerate(self.groups.keys()):
134 for i in range(len(artists[g])):
135 artists[g][i]._mt_plot_type = self

Callers

nothing calls this directly

Calls 2

keysMethod · 0.80
color_mapMethod · 0.45

Tested by

no test coverage detected