I'm trying to deal nicely with the clipping that happens when, for example, a line has data that is inside its clipping box, but the linewidth forces part of the line to be drawn outside of the clipping box. This is visible on the spine placement demo at http://matplotlib.sourceforge.net/examples/pylab_examples/spine_placement_demo.html, for example (the clipping at the top and bottom of most of the sine waves). This has been brought up here (or on the -devel list) before, and it was suggested to just set the clipping off, but that won't work in my case because sometimes I want to use that clipping box to limit the data shown.
The best solution I can think of is to expand the clipping box by padding it with the line width. For something like a scatter plot, I would also be okay with expanding the clipping box by padding by the max radius of a circle in the circle collection. However, I can't quite figure out how to do this with the transform framework. If I just pad the clip box using the padded() method, it seems to make it a static Bbox instead of a TransformedBbox, and my line disappears. Can someone help? Here is the example code I'm using. I don't know what to put in for the ???, which is all that I think I need. import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.plot([0,1],[1,1],lw=20) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.set_ylim([0,1]) line=ax.lines[0] # I still want clipping for things that are outside of the original clip box+linewidth padding # so I don't want to take off clipping; I guess it doesn't matter for this example, but it does for # more complicated examples. #line.set_clip_on(False) bb=line.get_clip_box() # How can I pad bb so that it is padded by linewidth/2*1.0/72*fig.dpi_scale_trans.transform_point([1,1]) dots? padded_bb=??? line.set_clip_box(padded_bb) fig.savefig('test.png') Another option I thought of was separating out masking the data from clipping the graphics. I suppose if I could get the data for the line and mask it to be within the clipbox, but then just set clipping off, I would still have the benefit of clipping things that were way outside of my bounding box, but letting things like an extra bit of linewidth through. However, this requires doing things like computing intersections of the line and the bounding box so that I can insert an extra point for the "end" of the line at the bounding box. This gets harder when the line is a spline or something like that. Thanks for being patient with me while I learn my way around matplotlib's excellent transformation framework. Jason -- Jason Grout ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users