not clipping objects in a plot

On this thread:

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg05383.html

clip_on was a suggested way of getting around the clipping that happens at the edge of a frame. In the Sage project, we are always setting the limits on the axes via set_xlim and set_ylim. Is there any way to get the lines and circles that pass across the edge of the usual clip boundary to still be drawn, even if we have set the xlim and ylim of the axis?

Basically (using an example from the gallery), is there a way to get the scatter plot circles below not clipped, while still having the y-axis only go from -2 to 2? If not, is there a way to easily calculate the protrusion of the various objects, like the circles below, so we know how much to adjust the axes to just include the circles?

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(0r,2*np.pi,100r)
y = 2*np.sin(x)
ax = fig.add_subplot(1,1,1)
q=ax.scatter(x,y)
ax.set_ylim([-2,2])
q.set_clip_on(False)
ax.set_clip_on(False)
ax.spines['left'].set_position(('outward',10))
ax.spines['bottom'].set_position(('outward',10))
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
fig.savefig('test.png')

Thanks,

Jason

Another idea would be to disable clipping specifically for any markers
at xlim[0] <= markerx <= xlim[1].

I'll talk about this with John and other interested parties at the SciPy
conference (will you be there?) and hopefully address this issue during
the sprint, where I'm planning to work on MPL.

-Andrew

···

jason-sage@...691... wrote:

On this thread:

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg05383.html

clip_on was a suggested way of getting around the clipping that happens
at the edge of a frame. In the Sage project, we are always setting the
limits on the axes via set_xlim and set_ylim. Is there any way to get
the lines and circles that pass across the edge of the usual clip
boundary to still be drawn, even if we have set the xlim and ylim of the
axis?

Basically (using an example from the gallery), is there a way to get the
scatter plot circles below not clipped, while still having the y-axis
only go from -2 to 2? If not, is there a way to easily calculate the
protrusion of the various objects, like the circles below, so we know
how much to adjust the axes to just include the circles?

I think this is just a vanilla bug that set_clip_on is being ignored for collections. That patch is rather straightforward.

Other developers: do you agree this should be fixed, or is there a good reason for current behavior that I'm missing?

Cheers,
Mike

Index: lib/matplotlib/collections.py

···

===================================================================
--- lib/matplotlib/collections.py (revision 7486)
+++ lib/matplotlib/collections.py (working copy)
@@ -207,8 +207,7 @@
         transform, transOffset, offsets, paths = self._prepare_points()

         gc = renderer.new_gc()
- gc.set_clip_rectangle(self.get_clip_box())
- gc.set_clip_path(self.get_clip_path())
+ self._set_gc_clip(gc)

         renderer.draw_path_collection(
             gc, transform.frozen(), paths, self.get_transforms(),
@@ -1211,8 +1210,7 @@
             transOffset = transOffset.get_affine()

         gc = renderer.new_gc()
- gc.set_clip_rectangle(self.get_clip_box())
- gc.set_clip_path(self.get_clip_path())
+ self._set_gc_clip(gc)

         if self._shading == 'gouraud':
             triangles, colors = self.convert_mesh_to_triangles(

jason-sage@...691... wrote:

On this thread:

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg05383.html

clip_on was a suggested way of getting around the clipping that happens at the edge of a frame. In the Sage project, we are always setting the limits on the axes via set_xlim and set_ylim. Is there any way to get the lines and circles that pass across the edge of the usual clip boundary to still be drawn, even if we have set the xlim and ylim of the axis?

Basically (using an example from the gallery), is there a way to get the scatter plot circles below not clipped, while still having the y-axis only go from -2 to 2? If not, is there a way to easily calculate the protrusion of the various objects, like the circles below, so we know how much to adjust the axes to just include the circles?

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(0r,2*np.pi,100r)
y = 2*np.sin(x)
ax = fig.add_subplot(1,1,1)
q=ax.scatter(x,y)
ax.set_ylim([-2,2])
q.set_clip_on(False)
ax.set_clip_on(False)
ax.spines['left'].set_position(('outward',10))
ax.spines['bottom'].set_position(('outward',10))
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
fig.savefig('test.png')

Thanks,

Jason

------------------------------------------------------------------------------
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-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

I think this is just a vanilla bug that set_clip_on is being ignored for collections. That patch is rather straightforward.

Other developers: do you agree this should be fixed, or is there a good reason for current behavior that I'm missing?

It certainly looks to me like an annoying bug, so if your patch fixes it, great!

Eric

···

Cheers,
Mike

Index: lib/matplotlib/collections.py

--- lib/matplotlib/collections.py (revision 7486)
+++ lib/matplotlib/collections.py (working copy)
@@ -207,8 +207,7 @@
         transform, transOffset, offsets, paths = self._prepare_points()

         gc = renderer.new_gc()
- gc.set_clip_rectangle(self.get_clip_box())
- gc.set_clip_path(self.get_clip_path())
+ self._set_gc_clip(gc)

         renderer.draw_path_collection(
             gc, transform.frozen(), paths, self.get_transforms(),
@@ -1211,8 +1210,7 @@
             transOffset = transOffset.get_affine()

         gc = renderer.new_gc()
- gc.set_clip_rectangle(self.get_clip_box())
- gc.set_clip_path(self.get_clip_path())
+ self._set_gc_clip(gc)

         if self._shading == 'gouraud':
             triangles, colors = self.convert_mesh_to_triangles(

jason-sage@...691... wrote:

On this thread:

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg05383.html

clip_on was a suggested way of getting around the clipping that happens at the edge of a frame. In the Sage project, we are always setting the limits on the axes via set_xlim and set_ylim. Is there any way to get the lines and circles that pass across the edge of the usual clip boundary to still be drawn, even if we have set the xlim and ylim of the axis?

Basically (using an example from the gallery), is there a way to get the scatter plot circles below not clipped, while still having the y-axis only go from -2 to 2? If not, is there a way to easily calculate the protrusion of the various objects, like the circles below, so we know how much to adjust the axes to just include the circles?

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(0r,2*np.pi,100r)
y = 2*np.sin(x)
ax = fig.add_subplot(1,1,1)
q=ax.scatter(x,y)
ax.set_ylim([-2,2])
q.set_clip_on(False)
ax.set_clip_on(False)
ax.spines['left'].set_position(('outward',10))
ax.spines['bottom'].set_position(('outward',10))
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
fig.savefig('test.png')

Thanks,

Jason

------------------------------------------------------------------------------
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-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  

Andrew Straw wrote:

  

On this thread:

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg05383.html

clip_on was a suggested way of getting around the clipping that happens at the edge of a frame. In the Sage project, we are always setting the limits on the axes via set_xlim and set_ylim. Is there any way to get the lines and circles that pass across the edge of the usual clip boundary to still be drawn, even if we have set the xlim and ylim of the axis?

Basically (using an example from the gallery), is there a way to get the scatter plot circles below not clipped, while still having the y-axis only go from -2 to 2? If not, is there a way to easily calculate the protrusion of the various objects, like the circles below, so we know how much to adjust the axes to just include the circles?
  

Another idea would be to disable clipping specifically for any markers
at xlim[0] <= markerx <= xlim[1].

I'll talk about this with John and other interested parties at the SciPy
conference (will you be there?) and hopefully address this issue during
the sprint, where I'm planning to work on MPL.

No, I won't be there, but I'm excited to hear what comes out of the sprint.

Andrew, thanks for suggesting a way to get this to work. Michael and Eric, thanks for finding a fix for the general problem.

I'm impressed at how quickly developers respond to questions here! I am really, really glad that Sage is using matplotlib for 2d graphics.

Thanks,

Jason

···

jason-sage@...691... wrote: