[matplotlib-devel] mplot3d line objects
Hello, I am working with the Line3D objects in the mplot3d toolkit. I have noticed that the .set_data() function is not overloaded from the Line class, therefore, there is no direct way to set the line data. Should a .set_data() function be created for Line3D or is there some inherent barrier to doing this? Also, would it make sense to add a .set_zdata() function as well? One probably could work around this by calling .set_data() on the 2D data, and then calling .set_3d_properties() with the z data, but I haven't tested this yet. Thanks, Ben Root -- This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] mplot3d line objects
Along the same vein, I have noticed that the Axes3D object does not have a .set_zlim() function, instead opting to use .set_zlim3d(). The same is true with xlim() and ylim(), implementing a different function for .set_xlim3d() than the inherited .set_xlim(). Is this intended? Thanks, Ben Root On Fri, Jul 2, 2010 at 2:28 PM, Benjamin Root wrote: > Hello, > > I am working with the Line3D objects in the mplot3d toolkit. I have > noticed that the .set_data() function is not overloaded from the Line class, > therefore, there is no direct way to set the line data. Should a > .set_data() function be created for Line3D or is there some inherent barrier > to doing this? Also, would it make sense to add a .set_zdata() function as > well? > > One probably could work around this by calling .set_data() on the 2D data, > and then calling .set_3d_properties() with the z data, but I haven't tested > this yet. > > Thanks, > Ben Root > -- This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
[matplotlib-devel] Help with blitting bug with subplots and markers
Hi, I've been debugging this for hours now and could really use the help of someone smarter than me. In working on blitting with animations, I've run into a problem when trying to use blitting + multiple subplots + lines with markers. It's an esoteric combination to be sure, but I have a script (attached) that demonstrates my problem. As far as I can tell, the addition of a marker to a line object causes to canvas.restore_region() to no longer function (I've paused the animation, after a blit to flush the draw, after every stage). The data in the region saved from copy_from_bbox is fine, but calling restore_region() with it has no effect. Removing marker from the line specification causes the problem to disappear. The net effect of the problem is that the other subplot (than the one with the marker) does not have the previous draw cleared, resulting in a smearing effect. Anybody have a clue? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma #!/usr/bin/env python # Reveals a bug in blitting with multiple subplots caused by the use of # markers import time import gtk, gobject import matplotlib matplotlib.use('GTKAgg') import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(121) ax2 = fig.add_subplot(122) canvas = fig.canvas fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs ax.grid() # to ensure proper background restore ax2.grid() # create the initial line x = np.arange(0,2*np.pi,0.01) line, = ax.plot(x, np.sin(x), animated=True, lw=2, marker='o') line2, = ax2.plot(x, np.cos(x), 'k', animated=True, lw=2) canvas.draw() def update_line(*args): if update_line.background is None: update_line.background = canvas.copy_from_bbox(ax.bbox) update_line.background2 = canvas.copy_from_bbox(ax2.bbox) canvas.restore_region(update_line.background) line.set_ydata(np.sin(x+update_line.cnt/10.0)) ax.draw_artist(line) canvas.blit(ax.bbox) canvas.restore_region(update_line.background2) line2.set_ydata(np.sin(x+update_line.cnt/10.0)) ax2.draw_artist(line2) canvas.blit(ax2.bbox) if update_line.cnt==1000: gtk.main_quit() raise SystemExit update_line.cnt += 1 return True update_line.cnt = 0 update_line.background = None def start_anim(event): gobject.timeout_add(100, update_line) canvas.mpl_disconnect(start_anim.cid) start_anim.cid = canvas.mpl_connect('draw_event', start_anim) plt.show() -- This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Help with blitting bug with subplots and markers
Alright, before I go to bed, I found the following line in src/_backend_agg.cpp at line 709 (in draw_markers()) makes all the difference: set_clipbox(gc.cliprect, rendererBase); Commenting out this line fixes my problem. I'm not sure why it's a problem, (maybe a missing restore to previous state somewhere?). I'll look into this tomorrow, but it would probably be a lot easier with someone familiar with the code. Ryan On Sat, Jul 3, 2010 at 12:33 AM, Ryan May wrote: > Hi, > > I've been debugging this for hours now and could really use the help > of someone smarter than me. In working on blitting with animations, > I've run into a problem when trying to use blitting + multiple > subplots + lines with markers. It's an esoteric combination to be > sure, but I have a script (attached) that demonstrates my problem. As > far as I can tell, the addition of a marker to a line object causes to > canvas.restore_region() to no longer function (I've paused the > animation, after a blit to flush the draw, after every stage). The > data in the region saved from copy_from_bbox is fine, but calling > restore_region() with it has no effect. Removing marker from the line > specification causes the problem to disappear. The net effect of the > problem is that the other subplot (than the one with the marker) does > not have the previous draw cleared, resulting in a smearing effect. > > Anybody have a clue? > > Ryan > > -- > Ryan May > Graduate Research Assistant > School of Meteorology > University of Oklahoma > -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
[matplotlib-devel] subplotting 3d figures
Hello all, I have always been a bit troubled with how Axes3D object is a bit of a 2nd-class citizen in matplotlib. In particular, it is very common to create a new axes using .add_subplot() or .gca(), but you can't do that with Axes3D. You also can't create subplots of 3d figures, you have to create multiple figures with single 3d plots in them. My examination off the code have not revealed anything that prevents this from happening. Currently, the gca() and add_subplot() functions accept a kwarg of 'projection' which allows one to specify the name of a registered axes object. Currently axes.Axes, polar and a few others are registered, with axes.Axes being default. I have found that 3 lines of code in the axes3d module to have it add the Axes3D class to the registry. Using a name of '3d', one can specify the projection to gain a Axes3d object. Note, you will still have to import the Axes3D object as usual. Attached is a patch for axes3d.py and a file that could be added to mpl_examples/. Give it a shot and let me know how it works for you! Enjoy! Ben Root P.S. - Can you just imagine subplots of animated 3d plots? wink... wink... Index: matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py === --- matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py (revision 8481) +++ matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py (working copy) @@ -37,6 +37,7 @@ """ 3D axes object. """ +name = '3d' def __init__(self, fig, rect=None, *args, **kwargs): ''' @@ -1210,3 +1211,11 @@ Z = Z * 500 return X, Y, Z + + + +# Register Axes3D as a 'projection' object available +# for use just like any other axes + +import matplotlib.projections as proj +proj.projection_registry.register(Axes3D) from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm #from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(1, 2, 1, projection='3d') X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False) ax.set_zlim3d(-1.01, 1.01) #ax.w_zaxis.set_major_locator(LinearLocator(10)) #ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f')) fig.colorbar(surf, shrink=0.5, aspect=5) from mpl_toolkits.mplot3d.axes3d import get_test_data ax = fig.add_subplot(1, 2, 2, projection='3d') X, Y, Z = get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) plt.show() -- This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel