I'm looking to create a type of rectangle that draws with a cross from corner to corner, all as a single class type. To do this, I've created a subtype of the rectange class, that records what the current axis is and tries to draw two lines to it in the draw function. When displayting the graph, initially the cross is not shown, but if I zoom/pan the graph, the cross appears. Can anyone see where my problem lies and possibly present a solution?
Cheers Ben from matplotlib.lines import Line2D from matplotlib.patches import Rectangle from pylab import figure, show class CrossRect(Rectangle): def __init__(self, ax, *args, **kwargs): Rectangle.__init__(self, *args, **kwargs) self.ax = ax def draw(self, renderer): Rectangle.draw(self, renderer) self._draw_cross() def _draw_cross(self): x=self.get_x() y=self.get_y() forward_slash=Line2D((x, x+self.get_width()), (y, y+self.get_height())) back_slash=Line2D((x, x+self.get_width()), (y+self.get_height(), y)) self.ax.add_line(forward_slash) self.ax.add_line(back_slash) fig = figure() ax = fig.add_subplot(111, autoscale_on=True) left, width, bottom, height = 5, 5, 5, 5 rect = CrossRect(ax, (left, bottom), width, height, fill=False) ax.add_patch(rect) ax.set_xlim(3,12) ax.set_ylim(3,12) show() -- View this message in context: http://www.nabble.com/Creating-custom-rectangle-tp20062265p20062265.html Sent from the matplotlib - users mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users