def _add_bar_graph(self, item, shading='faceted'): if DEBUG: print "Adding a bar graph" # get data: x = squeeze(item.getp('xdata')) y = squeeze(item.getp('ydata')) # get line specifiactions: marker, color, style, width = self._get_linespecs(item) edgecolor = item.getp('edgecolor') if not edgecolor: edgecolor = 'k' # use black for now # FIXME: edgecolor should be same as ax.getp('fgcolor') by default facecolor = item.getp('facecolor') if not facecolor: facecolor = color opacity = item.getp('material').getp('opacity') if opacity is None: opacity = 1.0 if y.ndim == 1: y = reshape(y,(len(y),1)) nx, ny = shape(y) step = item.getp('barstepsize')/10 center = floor(ny/2) start = -step*center stop = step*center if not ny%2: start += step/2 stop -= step/2 a = linspace(start,stop,ny) barwidth = item.getp('barwidth')/10 hold_state = self._g.ishold() self._g.hold(True) colors = PlotProperties._colors + \ list(matplotlib.colors.cnames.values()) for j in range(ny): y_ = y[:,j] x_ = array(list(range(nx))) + a[j] - barwidth/2 if not facecolor: c = colors[j] else: c = facecolor self._g.bar(x_, y_, width=barwidth, color=c, ec=edgecolor, alpha=opacity) self._g.hold(hold_state) barticks = item.getp('barticks') if barticks is None: barticks = x if item.getp('rotated_barticks'): self._g.xticks(list(range(len(x))), barticks, rotation=90) else: self._g.xticks(list(range(len(x))), barticks)
def _add_bars(self, name, item, shading='faceted'): if DEBUG: print("Adding a bar graph") # get data: x = item.getp('xdata') y = item.getp('ydata') # get line specifiactions: marker, color, style, width = self._get_linespecs(item) if y.ndim == 1: y = reshape(y, (len(y), 1)) nx, ny = shape(y) barticks = item.getp('barticks') if barticks is None: barticks = list(range(nx)) xtics = ', '.join(['"%s" %d' % (m, i) for i, m in enumerate(barticks)]) if item.getp('rotated_barticks'): pass barwidth = item.getp('barwidth') / 10 edgecolor = item.getp('edgecolor') if not edgecolor: edgecolor = 'black' # use black for now # FIXME: edgecolor should be same as ax.getp('fgcolor') by default else: edgecolor = self._colors.get(edgecolor, 'black') if shading == 'faceted': pass else: pass facecolor = item.getp('facecolor') if not facecolor: facecolor = color facecolor = self._colors.get(facecolor, 'blue') # use blue as default step = item.getp('barstepsize') / 10 center = floor(ny / 2) start = -step * center stop = step * center if not ny % 2: start += step / 2 stop -= step / 2 a = linspace(start, stop, ny) self._g.configure(barmode="overlap") data = [] for j in range(ny): y_ = y[:, j] x_ = array(list(range(nx))) + a[j] curvename = '%s_bar%s' % (name, j) if not item.getp('linecolor') and not item.getp('facecolor'): color = 'black' else: color = facecolor self._g.bar_create(curvename, xdata=tuple(x_), ydata=tuple(y_), barwidth=barwidth, fg=color)