def bar(self, left, height, zs=0, zdir='z', *args, **kwargs): ''' Add 2D bar(s). ========== ================================================ Argument Description ========== ================================================ *left* The x coordinates of the left sides of the bars. *height* The height of the bars. *zs* Z coordinate of bars, if one value is specified they will all be placed at the same z. *zdir* Which direction to use as z ('x', 'y' or 'z') when plotting a 2d set. ========== ================================================ Keyword arguments are passed onto :func:`~matplotlib.axes.Axes.bar`. Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection` ''' had_data = self.has_data() patches = Axes.bar(self, left, height, *args, **kwargs) if not cbook.iterable(zs): zs = np.ones(len(left))*zs verts = [] verts_zs = [] for p, z in zip(patches, zs): vs = p.get_verts() verts += vs.tolist() verts_zs += [z] * len(vs) art3d.patch_2d_to_3d(p, zs, zdir) if 'alpha' in kwargs: p.set_alpha(kwargs['alpha']) xs, ys = zip(*verts) xs, ys, verts_zs = art3d.juggle_axes(xs, ys, verts_zs, zdir) self.auto_scale_xyz(xs, ys, verts_zs, had_data) return patches
def bar(self, left, height, z=0, dir='z', *args, **kwargs): had_data = self.has_data() patches = self.wrapped.bar(left, height, *args, **kwargs) # verts = [] for p in patches: vs = p.get_verts() zs = [z]*len(vs) verts += vs patch3d = art3d.Patch3D(p, zs, dir=dir) xs,ys = zip(*verts) zs = [z]*len(xs) xs,ys,zs=art3d.juggle_axes(xs,ys,zs,dir) self.wrapped.auto_scale_xyz(xs,ys,zs, had_data)
def plot(self, *args, **kwargs): had_data = self.has_data() zval = cbook.popd(kwargs, 'z', 0) zdir = cbook.popd(kwargs, 'dir', 'z') lines = Axes.plot(self, *args, **kwargs) # linecs = [art3d.Line2DW(l, z=zval, dir=zdir) for l in lines] # xs = lines[0].get_xdata() ys = lines[0].get_ydata() zs = [zval for x in xs] xs,ys,zs = art3d.juggle_axes(xs,ys,zs,zdir) # self.auto_scale_xyz(xs,ys,zs, had_data) # return linecs
def bar(self, left, height, zs=0, zdir='z', *args, **kwargs): ''' Add 2D bar(s). ========== ================================================ Argument Description ========== ================================================ *left* The x coordinates of the left sides of the bars. *height* The height of the bars. *zs* Z coordinate of bars, if one value is specified they will all be placed at the same z. *zdir* Which direction to use as z ('x', 'y' or 'z') when plotting a 2d set. ========== ================================================ Keyword arguments are passed onto :func:`~matplotlib.axes.Axes.bar`. Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection` ''' had_data = self.has_data() patches = Axes.bar(self, left, height, *args, **kwargs) if not cbook.iterable(zs): zs = np.ones(len(left)) * zs verts = [] verts_zs = [] for p, z in zip(patches, zs): vs = art3d.get_patch_verts(p) verts += vs.tolist() verts_zs += [z] * len(vs) art3d.patch_2d_to_3d(p, zs, zdir) if 'alpha' in kwargs: p.set_alpha(kwargs['alpha']) xs, ys = zip(*verts) xs, ys, verts_zs = art3d.juggle_axes(xs, ys, verts_zs, zdir) self.auto_scale_xyz(xs, ys, verts_zs, had_data) return patches
def draw(self, renderer): self.label._transform = self.axes.transData renderer.open_group('axis3d') majorTicks = self.get_major_ticks() majorLocs = self.major.locator() interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ interval[0] < loc < interval[1]] self.major.formatter.set_locs(majorLocs) majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)] minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() mins = np.array((minx, miny, minz)) maxs = np.array((maxx, maxy, maxz)) centers = (maxs + mins) / 2. deltas = (maxs - mins) / 12. mins = mins - deltas / 4. maxs = maxs + deltas / 4. vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] highs = np.array([avgz[2*i] < avgz[2*i+1] for i in range(3)]) info = self._AXINFO[self.adir] index = info['i'] if not highs[index]: plane = self._PLANES[2 * index] else: plane = self._PLANES[2 * index + 1] xys = [tc[p] for p in plane] self.set_pane(xys, info['color']) self.pane.draw(renderer) minmax = np.where(highs, maxs, mins) juggled = art3d.juggle_axes(0, 2, 1, self.adir) edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) self.line.draw(renderer) xyz0 = [] for val in majorLocs: coord = minmax.copy() coord[index] = val xyz0.append(coord) dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] lxyz = 0.5*(edgep1 + edgep2) labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) self.label.set_position((tlx, tly)) if self.get_rotate_label(self.label.get_text()): angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.label.set_rotation(angle) self.label.set_va('center') self.label.draw(renderer) xyz1 = copy.deepcopy(xyz0) newindex = (index + 1) % 3 newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz1[i][newindex] = newval xyz2 = copy.deepcopy(xyz0) newindex = (index + 2) % 3 newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz2[i][newindex] = newval lines = zip(xyz1, xyz0, xyz2) if self.axes._draw_grid: self.gridlines.set_segments(lines) self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines)) self.gridlines.draw(renderer, project=True) tickdir = info['tickdir'] tickdelta = deltas[tickdir] if highs[tickdir]: ticksign = 1 else: ticksign = -1 for tick, loc, label in zip(majorTicks, majorLocs, majorLabels): if tick is None: continue pos = copy.copy(edgep1) pos[index] = loc pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) labeldeltas = [0.6 * x for x in deltas] axmask = [True, True, True] axmask[index] = False pos[tickdir] = edgep1[tickdir] pos = move_from_center(pos, centers, labeldeltas, axmask) lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly)) tick.set_label1(label) tick.set_label2(label) tick.draw(renderer) renderer.close_group('axis3d')
def draw(self, renderer): self.label._transform = self.axes.transData renderer.open_group('axis3d') # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ interval[0] < loc < interval[1]] self.major.formatter.set_locs(majorLocs) majorLabels = [ self.major.formatter(val, i) for i, val in enumerate(majorLocs) ] # Determine bounds minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() mins = np.array((minx, miny, minz)) maxs = np.array((maxx, maxy, maxz)) centers = (maxs + mins) / 2. deltas = (maxs - mins) / 12. mins = mins - deltas / 4. maxs = maxs + deltas / 4. # Determine which planes should be visible by the avg z value vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) #raise RuntimeError('WTF: p1=%s'%p1) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] highs = np.array([avgz[2 * i] < avgz[2 * i + 1] for i in range(3)]) # Draw plane info = self._AXINFO[self.adir] index = info['i'] if not highs[index]: plane = self._PLANES[2 * index] else: plane = self._PLANES[2 * index + 1] xys = [tc[p] for p in plane] self.set_pane(xys, info['color']) self.pane.draw(renderer) # Determine grid lines minmax = np.where(highs, maxs, mins) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) self.line.draw(renderer) # Grid points where the planes meet xyz0 = [] for val in majorLocs: coord = minmax.copy() coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] lxyz = 0.5 * (edgep1 + edgep2) labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) self.label.set_position((tlx, tly)) if self.get_rotate_label(self.label.get_text()): angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.label.set_rotation(angle) self.label.set_va('center') self.label.draw(renderer) # Grid points at end of one plane xyz1 = copy.deepcopy(xyz0) newindex = (index + 1) % 3 newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz1[i][newindex] = newval # Grid points at end of the other plane xyz2 = copy.deepcopy(xyz0) newindex = (index + 2) % 3 newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz2[i][newindex] = newval lines = zip(xyz1, xyz0, xyz2) if self.axes._draw_grid: self.gridlines.set_segments(lines) self.gridlines.set_color([(0.9, 0.9, 0.9, 1)] * len(lines)) self.gridlines.draw(renderer, project=True) # Draw ticks tickdir = info['tickdir'] tickdelta = deltas[tickdir] if highs[tickdir]: ticksign = 1 else: ticksign = -1 for tick, loc, label in zip(majorTicks, majorLocs, majorLabels): if tick is None: continue # Get tick line positions pos = copy.copy(edgep1) pos[index] = loc pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) # Get position of label labeldeltas = [0.6 * x for x in deltas] axmask = [True, True, True] axmask[index] = False pos[tickdir] = edgep1[tickdir] pos = move_from_center(pos, centers, labeldeltas, axmask) lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly)) tick.set_label1(label) tick.set_label2(label) tick.draw(renderer) renderer.close_group('axis3d')
def draw(self, renderer): self.label._transform = self.axes.transData renderer.open_group('axis3d') # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() info = self._AXINFO[self.adir] index = info['i'] # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ interval[0] < loc < interval[1]] self.major.formatter.set_locs(majorLocs) majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)] mins, maxs, centers, deltas, tc, highs = self._get_coord_info(renderer) # Determine grid lines minmax = np.where(highs, maxs, mins) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) self.line.draw(renderer) # Grid points where the planes meet xyz0 = [] for val in majorLocs: coord = minmax.copy() coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] lxyz = 0.5*(edgep1 + edgep2) labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) self.label.set_position((tlx, tly)) if self.get_rotate_label(self.label.get_text()): angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.label.set_rotation(angle) self.label.set_va('center') self.label.draw(renderer) # Grid points at end of one plane xyz1 = copy.deepcopy(xyz0) newindex = (index + 1) % 3 newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz1[i][newindex] = newval # Grid points at end of the other plane xyz2 = copy.deepcopy(xyz0) newindex = (index + 2) % 3 newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz2[i][newindex] = newval lines = zip(xyz1, xyz0, xyz2) if self.axes._draw_grid: self.gridlines.set_segments(lines) self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines)) self.gridlines.draw(renderer, project=True) # Draw ticks tickdir = info['tickdir'] tickdelta = deltas[tickdir] if highs[tickdir]: ticksign = 1 else: ticksign = -1 for tick, loc, label in zip(majorTicks, majorLocs, majorLabels): if tick is None: continue # Get tick line positions pos = copy.copy(edgep1) pos[index] = loc pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) # Get position of label labeldeltas = [0.6 * x for x in deltas] axmask = [True, True, True] axmask[index] = False pos[tickdir] = edgep1[tickdir] pos = move_from_center(pos, centers, labeldeltas, axmask) lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly)) tick.set_label1(label) tick.set_label2(label) tick.draw(renderer) renderer.close_group('axis3d')
def draw(self, renderer): self.label._transform = self.axes.transData renderer.open_group('axis3d') # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ interval[0] < loc < interval[1]] self.major.formatter.set_locs(majorLocs) majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)] # Determine bounds minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() mins = (minx, miny, minz) maxs = (maxx, maxy, maxz) centers = [(maxv + minv) / 2 for minv, maxv in zip(mins, maxs)] deltas = [(maxv - minv) / 12 for minv, maxv in zip(mins, maxs)] mins = [minv - delta / 4 for minv, delta in zip(mins, deltas)] maxs = [maxv + delta / 4 for maxv, delta in zip(maxs, deltas)] # Determine which planes should be visible by the avg z value vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] highs = [avgz[2*i] < avgz[2*i+1] for i in range(3)] # Draw plane info = self._AXINFO[self.adir] index = info['i'] if not highs[index]: plane = self._PLANES[2 * index] else: plane = self._PLANES[2 * index + 1] xys = [tc[p] for p in plane] self.set_pane(xys, info['color']) self.pane.draw(renderer) # Determine grid lines minmax = [] for i, val in enumerate(highs): if val: minmax.append(maxs[i]) else: minmax.append(mins[i]) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) edgep1 = copy.copy(minmax) edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) edgep2 = copy.copy(edgep1) edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) self.line.draw(renderer) # Grid points where the planes meet xyz0 = [] for val in majorLocs: coord = copy.copy(minmax) coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] lxyz = [(v1 + v2) / 2 for v1, v2 in zip(edgep1, edgep2)] labeldeltas = [1.3 * x for x in deltas] lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) self.label.set_position((tlx, tly)) if self.get_rotate_label(self.label.get_text()): angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.label.set_rotation(angle) self.label.set_va('center') self.label.draw(renderer) # Grid points at end of one plane xyz1 = copy.deepcopy(xyz0) newindex = (index + 1) % 3 newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz1[i][newindex] = newval # Grid points at end of the other plane xyz2 = copy.deepcopy(xyz0) newindex = (index + 2) % 3 newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz2[i][newindex] = newval lines = zip(xyz1, xyz0, xyz2) if self.axes._draw_grid: self.gridlines.set_segments(lines) self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines)) self.gridlines.draw(renderer, project=True) # Draw ticks tickdir = info['tickdir'] tickdelta = deltas[tickdir] if highs[tickdir]: ticksign = 1 else: ticksign = -1 for tick, loc, label in zip(majorTicks, majorLocs, majorLabels): if tick is None: continue # Get tick line positions pos = copy.copy(edgep1) pos[index] = loc pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) # Get position of label labeldeltas = [0.6 * x for x in deltas] axmask = [True, True, True] axmask[index] = False pos[tickdir] = edgep1[tickdir] pos = move_from_center(pos, centers, labeldeltas, axmask) lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2], \ renderer.M) tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly)) tick.set_label1(label) tick.set_label2(label) tick.draw(renderer) renderer.close_group('axis3d')