def time_sum_chart(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) size = len(values) x = xrange(size) n, bins, patches = ax.hist(x, size, range=(0, size), weights=values, facecolor='green', alpha=0.75) xticks = map(lambda x: x+0.5, x) ax.set_xticks(xticks) ax.set_xticklabels(names) for label in ax.xaxis.get_ticklabels(): label.set_fontsize(7) label.set_rotation(-45) label.set_horizontalalignment('left') ax.yaxis.set_major_formatter(mpl_FuncFormatter( lambda time, pos: utils.time_to_string(time)[:10])) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure, with_legend=False, xlock=True)
def histogram(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) colors = [cm.hsv(float(i)/len(values)) for i in xrange(len(values))] n, bins, patches = ax.hist( values, 10, normed=0, histtype="bar", label=names, color=colors) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') ax.plegend = ax.legend(loc="upper right", fancybox=True, shadow=True) ax.xaxis.set_major_formatter(mpl_FuncFormatter( lambda time, pos: utils.time_to_string(time)[:-7])) ax.set_xlim(xmin=0) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure, xlock=True)
def histogram(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) colors = [cm.hsv(float(i) / len(values)) for i in xrange(len(values))] n, bins, patches = ax.hist(values, 10, normed=0, histtype="bar", label=names, color=colors) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') ax.plegend = ax.legend(loc="upper right", fancybox=True, shadow=True) ax.xaxis.set_major_formatter( mpl_FuncFormatter(lambda time, pos: utils.time_to_string(time)[:-7])) ax.set_xlim(xmin=0) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure, xlock=True)
def histogram(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) lines_config = [] cpalete = cm.get_cmap() vals_size = len(values) for i, vals in enumerate(values): times = [time for time, val in vals.items()] times.sort() new_x, new_y = [], [] values_len = 0 for time in times: time_range = time // 5000 if time_range < values_len: new_y[time_range] += vals[time] else: new_x.append(time) new_y.append(vals[time]) values_len += 1 if len(new_y) > 0: # TODO: how to add correct version of x-axis values?? xvals = range(0, values_len) color = cm.Paired(float(i)/vals_size) line, = ax.plot(xvals, new_y, color=color, lw=1, label=names[i]) lines_config.append(LineConfig(line, xvals, new_y, color)) for label in ax.xaxis.get_ticklabels(): label.set_fontsize(9) label.set_rotation(-35) label.set_horizontalalignment('left') ax.plegend = ax.legend(loc="upper right", fancybox=True, shadow=True) _register_histogram_pick_legend(ax, ax.plegend, lines_config) ax.xaxis.set_major_formatter(mpl_FuncFormatter( lambda time, pos: utils.time_to_string(time)[:-7])) ax.set_xlim(xmin=0) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure)
def place_chart(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) llines = [] for line, name in enumerate(names): xvalues, yvalues = zip(*values[line]) llines.append((name, xvalues, yvalues)) # fill data lines_config = [] for ldata in llines: name, xvalues, yvalues = ldata line, = ax.plot( xvalues, yvalues, 'o-', drawstyle='steps-post', label=name) lines_config.append( LineConfig(line, xvalues, yvalues, line.get_color())) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') # set legend ax.plegend = ax.legend(loc="upper left", fancybox=True, shadow=True) ax.register_pick_legend(ax.plegend, lines_config) ax.xaxis.set_major_formatter(mpl_FuncFormatter( lambda time, pos: utils.time_to_string(time)[:-7])) # set basic properties ax.set_xlim(xmin = 0) ax.get_figure().tight_layout() ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure)
def place_chart(names, values, title="", xlabel="", ylabel=""): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) ax = figure.add_subplot(111, projection=BasicChart.name) # fill data lines_config = [] for i, (xvalues, yvalues) in enumerate(values): line, = ax.plot(xvalues, yvalues, 'o-', drawstyle="steps-post", label=names[i]) lines_config.append( LineConfig(line, xvalues, yvalues, line.get_color())) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') # set legend ax.plegend = ax.legend(loc="upper left", fancybox=True, shadow=True) ax.register_pick_legend(ax.plegend, lines_config) ax.xaxis.set_major_formatter( mpl_FuncFormatter(lambda time, pos: utils.time_to_string(time)[:-7])) # set basic properties ax.set_xlim(xmin=0) ax.get_figure().tight_layout() ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) return ChartWidget(figure)
def utilization_chart(names, values, title="", xlabel="", ylabel="", idles=None): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) # TODO: Change it to TimeChart ax = figure.add_subplot(111, projection=BasicChart.name) ywidth = 2 yticks = [] if idles is not None: for i, lidle in enumerate(idles): y = ((i+1) * ywidth) + (i+1) ax.broken_barh( lidle, (y, ywidth), edgecolor='face', facecolor='#EAA769') for i, ldata in enumerate(values): y = (ywidth+1) * (i+ 1) yticks.append(y + ywidth/2) ax.broken_barh( ldata, (y, ywidth), edgecolor='face', facecolor='green') ax.set_yticks(yticks) ax.set_yticklabels(names) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') for i, label in enumerate(ax.yaxis.get_ticklabels()): # add 3 white space on the begining of name names[i] = " %s" % names[i] label.set_horizontalalignment("left") label.set_verticalalignment('center') p = mpl_Rectangle((0, 0), 1, 1, edgecolor='green', fc='green', alpha=0.75) if idles is not None: idle_leg = mpl_Rectangle((0,0), 1, 1, edgecolor='#eaa769', fc='#eaa769', alpha=0.75) ax.plegend = ax.legend( [p,idle_leg], ["Running", "Idle"], loc="upper left", fancybox=True, shadow=True) else: ax.plegend = ax.legend( [p], ["Running"], loc="upper left", fancybox=True, shadow=True) ax.xaxis.grid(True, linestyle="-", which='major', color='black', alpha=0.7) ax.xaxis.set_major_formatter(mpl_FuncFormatter( lambda time, pos: utils.time_to_string(time)[:-7])) ax.set_xlim(xmin=0) ax.get_figure().tight_layout() ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) # resize figure w, h = figure.get_size_inches() figure.set_size_inches(w, len(values) * 0.4) return ChartWidget(figure, ylock=True)
def utilization_chart(names, values, title="", xlabel="", ylabel="", idles=None): if not names or not values: return _empty_chart(title, xlabel, ylabel) figure = mpl_Figure() canvas = mpl_FigureCanvas(figure) figure.set_canvas(canvas) # TODO: Change it to TimeChart ax = figure.add_subplot(111, projection=BasicChart.name) ywidth = 2 yticks = [] if idles is not None: for i, lidle in enumerate(idles): y = ((i + 1) * ywidth) + (i + 1) ax.broken_barh(lidle, (y, ywidth), edgecolor='face', facecolor='#EAA769') for i, ldata in enumerate(values): y = (ywidth + 1) * (i + 1) yticks.append(y + ywidth / 2) ax.broken_barh(ldata, (y, ywidth), edgecolor='face', facecolor='green') ax.set_yticks(yticks) ax.set_yticklabels(names) for label in ax.xaxis.get_ticklabels(): label.set_rotation(-35) label.set_horizontalalignment('left') for i, label in enumerate(ax.yaxis.get_ticklabels()): # add 3 white space on the begining of name names[i] = " %s" % names[i] label.set_horizontalalignment("left") label.set_verticalalignment('center') p = mpl_Rectangle((0, 0), 1, 1, edgecolor='green', fc='green', alpha=0.75) if idles is not None: idle_leg = mpl_Rectangle((0, 0), 1, 1, edgecolor='#eaa769', fc='#eaa769', alpha=0.75) ax.plegend = ax.legend([p, idle_leg], ["Running", "Idle"], loc="upper left", fancybox=True, shadow=True) else: ax.plegend = ax.legend([p], ["Running"], loc="upper left", fancybox=True, shadow=True) ax.xaxis.grid(True, linestyle="-", which='major', color='black', alpha=0.7) ax.xaxis.set_major_formatter( mpl_FuncFormatter(lambda time, pos: utils.time_to_string(time)[:-7])) ax.set_xlim(xmin=0) ax.get_figure().tight_layout() ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) # resize figure w, h = figure.get_size_inches() figure.set_size_inches(w, len(values) * 0.4) return ChartWidget(figure, ylock=True)