|
From: arsbbr <ar...@gm...> - 2010-07-24 12:18:45
|
Hi, i'm trying to make a simple 3d plot of a cylinder with plot_surface. There are two problems in my output: 1) the shading, shading does not work on the cylindric shell and at the same time produces weird artifacts on the top cover. http://old.nabble.com/file/p29254649/cyl-shade-error.png 2) Sometimes, not reproducible, the inner back of the cylindric shell is plotted in front of the top cover. It seems, that it depends somehow on the order of the plot commands, so that switching the two plot command helps... but not all the time. http://old.nabble.com/file/p29254649/cyl-clip-error.png Am I doing something fundamentally wrong here? ########################## from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np from matplotlib import cm fig = plt.figure() ax = Axes3D(fig) # Cylindrical shell phi = np.linspace(0, 2 * np.pi, 100) r = np.ones(100) h = np.linspace(0, 1, 100) x = 10 * np.outer(np.cos(phi), r) y = 10 * np.outer(np.sin(phi), r) z = 10 * np.outer(np.ones(np.size(r)), h) # Top cover phi_a = np.linspace(0, 2 * np.pi, 100) h_2 = np.ones(100) r_2 = np.linspace(0, 1, 100) x_2 = 10 * np.outer(np.cos(phi), r_2) y_2 = 10 * np.outer(np.sin(phi), r_2) z_2 = 10 * np.ones([100,100]) ax.plot_surface(x, y, z, rstride=9, cstride=15, linewidth=1, alpha=1) ax.plot_surface(x_2, y_2, z_2, rstride=5, cstride=20, linewidth=1, alpha=1) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show() ########################## I'm just a beginner and installed the Enthought Python Distribution 6.2-2, which unfortunately does not use the matplotlib version 1.0. Since I could not find the .egg install file on the matplotlib site I guess I'll have to wait until they update EPD.... self compiling is not a real option for me. Thanks any suggestions! -- View this message in context: http://old.nabble.com/plot_surface-shading-and-clipping-error-tp29254649p29254649.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Benjamin R. <ben...@ou...> - 2010-07-24 19:24:18
|
On Sat, Jul 24, 2010 at 7:18 AM, arsbbr <ar...@gm...> wrote: > > Hi, > i'm trying to make a simple 3d plot of a cylinder with plot_surface. > There are two problems in my output: > 1) the shading, shading does not work on the cylindric shell and at the > same > time produces weird > artifacts on the top cover. > http://old.nabble.com/file/p29254649/cyl-shade-error.png > > 2) Sometimes, not reproducible, the inner back of the cylindric shell is > plotted in front of the top cover. It seems, that it depends somehow on the > order of the plot commands, so that switching the two plot command helps... > but not all the time. > http://old.nabble.com/file/p29254649/cyl-clip-error.png > > Am I doing something fundamentally wrong here? > > ########################## > from mpl_toolkits.mplot3d import Axes3D > import matplotlib.pyplot as plt > import numpy as np > from matplotlib import cm > fig = plt.figure() > ax = Axes3D(fig) > > > # Cylindrical shell > phi = np.linspace(0, 2 * np.pi, 100) > r = np.ones(100) > h = np.linspace(0, 1, 100) > > > x = 10 * np.outer(np.cos(phi), r) > y = 10 * np.outer(np.sin(phi), r) > z = 10 * np.outer(np.ones(np.size(r)), h) > > > # Top cover > phi_a = np.linspace(0, 2 * np.pi, 100) > h_2 = np.ones(100) > r_2 = np.linspace(0, 1, 100) > > x_2 = 10 * np.outer(np.cos(phi), r_2) > y_2 = 10 * np.outer(np.sin(phi), r_2) > z_2 = 10 * np.ones([100,100]) > > ax.plot_surface(x, y, z, rstride=9, cstride=15, linewidth=1, alpha=1) > ax.plot_surface(x_2, y_2, z_2, rstride=5, cstride=20, linewidth=1, > alpha=1) > > ax.set_xlabel('X') > ax.set_ylabel('Y') > ax.set_zlabel('Z') > > plt.show() > ########################## > > > I'm just a beginner and installed the Enthought Python Distribution 6.2-2, > which unfortunately > does not use the matplotlib version 1.0. Since I could not find the .egg > install file on the matplotlib site I guess I'll have to wait until they > update EPD.... self compiling is not a real option for me. > > Thanks any suggestions! > > arsbbr, The second problem you mention is a known issue with 3D axes and it is largely due to issues with overlapping objects and trying to determine which one gets displayed on top of the other in a 3D -> 2D environment (oh, how I wish holographic displays were a reality!). You will find that viewing an object from certain angles will cause this issue, and then slightly moving away from those angles will make everything right again. Unfortunately, I do not anticipate this issue being solved anytime soon, although it probably should become a higher priority to me. I think I have seen the first issue before, but I never fully explored it. I think I just found my mini-project for the weekend! I will let you know what I find. Ben Root |
|
From: arsbbr <ar...@gm...> - 2010-07-24 19:46:13
|
Thank you for looking into it! It would be perfectly fine for me to merge the two objects, so that one surface_plot command will do it. Maybe someone can give me a hint how to accomplish that? I appreciate any tips. Benjamin Root-2 wrote: > > On Sat, Jul 24, 2010 at 7:18 AM, arsbbr <ar...@gm...> wrote: > >> >> Hi, >> i'm trying to make a simple 3d plot of a cylinder with plot_surface. >> There are two problems in my output: >> 1) the shading, shading does not work on the cylindric shell and at the >> same >> time produces weird >> artifacts on the top cover. >> http://old.nabble.com/file/p29254649/cyl-shade-error.png >> >> 2) Sometimes, not reproducible, the inner back of the cylindric shell is >> plotted in front of the top cover. It seems, that it depends somehow on >> the >> order of the plot commands, so that switching the two plot command >> helps... >> but not all the time. >> http://old.nabble.com/file/p29254649/cyl-clip-error.png >> >> Am I doing something fundamentally wrong here? >> >> ########################## >> from mpl_toolkits.mplot3d import Axes3D >> import matplotlib.pyplot as plt >> import numpy as np >> from matplotlib import cm >> fig = plt.figure() >> ax = Axes3D(fig) >> >> >> # Cylindrical shell >> phi = np.linspace(0, 2 * np.pi, 100) >> r = np.ones(100) >> h = np.linspace(0, 1, 100) >> >> >> x = 10 * np.outer(np.cos(phi), r) >> y = 10 * np.outer(np.sin(phi), r) >> z = 10 * np.outer(np.ones(np.size(r)), h) >> >> >> # Top cover >> phi_a = np.linspace(0, 2 * np.pi, 100) >> h_2 = np.ones(100) >> r_2 = np.linspace(0, 1, 100) >> >> x_2 = 10 * np.outer(np.cos(phi), r_2) >> y_2 = 10 * np.outer(np.sin(phi), r_2) >> z_2 = 10 * np.ones([100,100]) >> >> ax.plot_surface(x, y, z, rstride=9, cstride=15, linewidth=1, alpha=1) >> ax.plot_surface(x_2, y_2, z_2, rstride=5, cstride=20, linewidth=1, >> alpha=1) >> >> ax.set_xlabel('X') >> ax.set_ylabel('Y') >> ax.set_zlabel('Z') >> >> plt.show() >> ########################## >> >> >> I'm just a beginner and installed the Enthought Python Distribution >> 6.2-2, >> which unfortunately >> does not use the matplotlib version 1.0. Since I could not find the .egg >> install file on the matplotlib site I guess I'll have to wait until they >> update EPD.... self compiling is not a real option for me. >> >> Thanks any suggestions! >> >> > arsbbr, > > The second problem you mention is a known issue with 3D axes and it is > largely due to issues with overlapping objects and trying to determine > which > one gets displayed on top of the other in a 3D -> 2D environment (oh, how > I > wish holographic displays were a reality!). You will find that viewing an > object from certain angles will cause this issue, and then slightly moving > away from those angles will make everything right again. Unfortunately, I > do not anticipate this issue being solved anytime soon, although it > probably > should become a higher priority to me. > > I think I have seen the first issue before, but I never fully explored it. > I think I just found my mini-project for the weekend! I will let you know > what I find. > > 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-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://old.nabble.com/plot_surface-shading-and-clipping-error-tp29254649p29256632.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Benjamin R. <ben...@ou...> - 2010-07-24 20:32:50
|
On Sat, Jul 24, 2010 at 2:46 PM, arsbbr <ar...@gm...> wrote: > > Thank you for looking into it! > It would be perfectly fine for me to merge the two objects, so that one > surface_plot command will do it. > Maybe someone can give me a hint how to accomplish that? > > I appreciate any tips. > > > > Benjamin Root-2 wrote: > > > > On Sat, Jul 24, 2010 at 7:18 AM, arsbbr <ar...@gm...> wrote: > > > >> > >> Hi, > >> i'm trying to make a simple 3d plot of a cylinder with plot_surface. > >> There are two problems in my output: > >> 1) the shading, shading does not work on the cylindric shell and at the > >> same > >> time produces weird > >> artifacts on the top cover. > >> http://old.nabble.com/file/p29254649/cyl-shade-error.png > >> > >> 2) Sometimes, not reproducible, the inner back of the cylindric shell is > >> plotted in front of the top cover. It seems, that it depends somehow on > >> the > >> order of the plot commands, so that switching the two plot command > >> helps... > >> but not all the time. > >> http://old.nabble.com/file/p29254649/cyl-clip-error.png > >> > >> Am I doing something fundamentally wrong here? > >> > >> ########################## > >> from mpl_toolkits.mplot3d import Axes3D > >> import matplotlib.pyplot as plt > >> import numpy as np > >> from matplotlib import cm > >> fig = plt.figure() > >> ax = Axes3D(fig) > >> > >> > >> # Cylindrical shell > >> phi = np.linspace(0, 2 * np.pi, 100) > >> r = np.ones(100) > >> h = np.linspace(0, 1, 100) > >> > >> > >> x = 10 * np.outer(np.cos(phi), r) > >> y = 10 * np.outer(np.sin(phi), r) > >> z = 10 * np.outer(np.ones(np.size(r)), h) > >> > >> > >> # Top cover > >> phi_a = np.linspace(0, 2 * np.pi, 100) > >> h_2 = np.ones(100) > >> r_2 = np.linspace(0, 1, 100) > >> > >> x_2 = 10 * np.outer(np.cos(phi), r_2) > >> y_2 = 10 * np.outer(np.sin(phi), r_2) > >> z_2 = 10 * np.ones([100,100]) > >> > >> ax.plot_surface(x, y, z, rstride=9, cstride=15, linewidth=1, alpha=1) > >> ax.plot_surface(x_2, y_2, z_2, rstride=5, cstride=20, linewidth=1, > >> alpha=1) > >> > >> ax.set_xlabel('X') > >> ax.set_ylabel('Y') > >> ax.set_zlabel('Z') > >> > >> plt.show() > >> ########################## > >> > >> > >> I'm just a beginner and installed the Enthought Python Distribution > >> 6.2-2, > >> which unfortunately > >> does not use the matplotlib version 1.0. Since I could not find the .egg > >> install file on the matplotlib site I guess I'll have to wait until they > >> update EPD.... self compiling is not a real option for me. > >> > >> Thanks any suggestions! > >> > >> > > arsbbr, > > > > The second problem you mention is a known issue with 3D axes and it is > > largely due to issues with overlapping objects and trying to determine > > which > > one gets displayed on top of the other in a 3D -> 2D environment (oh, how > > I > > wish holographic displays were a reality!). You will find that viewing > an > > object from certain angles will cause this issue, and then slightly > moving > > away from those angles will make everything right again. Unfortunately, > I > > do not anticipate this issue being solved anytime soon, although it > > probably > > should become a higher priority to me. > > > > I think I have seen the first issue before, but I never fully explored > it. > > I think I just found my mini-project for the weekend! I will let you > know > > what I find. > > > Actually, looks like your problem was relatively simple. The construction of the top surface wasn't done quite right and the striding was causing blocks to be skipped. Try this: phi_grid, r_grid = np.meshgrid(phi_a, r_2) x_2 = 10 * np.cos(phi_grid) * r_grid y_2 = 10 * np.sin(phi_grid) * r_grid z_2 = 10 * np.ones([100,100]) The thing to keep in mind when creating a surface in 3d is that the data needs to be considered as parameterizable in 2D and constructed as such. I hope that helps, Ben Root |
|
From: arsbbr <ar...@gm...> - 2010-07-25 10:19:24
|
Thanks, this was quite a tiny weekend project for you :) I'll keep you tip in mind. Concerning the foreground/background issue: The problem here seems quite random. It does not depend on the viewing angle. I rather just have to be lucky everytime the plot command is executed. If the plotting went right, I can rotate everything without any errors. I'm by no means a coder, but I find it hard to understand that executing the same script leads to a different outcome. My plan is to make a movie of the cylinder while shrinking. If the problem would just depend on the viewing angle, I would find a 'good angle', make it constant and start the loop. But at the moment the outcome is just arbitrary. Regards, arsbbr Benjamin Root-2 wrote: > > On Sat, Jul 24, 2010 at 2:46 PM, arsbbr <ar...@gm...> wrote: > > > > The thing to keep in mind when creating a surface in 3d is that the data > needs to be considered as parameterizable in 2D and constructed as such. > > I hope that helps, > > 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-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://old.nabble.com/plot_surface-shading-and-clipping-error-tp29254649p29259207.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Benjamin R. <ben...@ou...> - 2010-07-25 16:06:58
|
On Sun, Jul 25, 2010 at 5:19 AM, arsbbr <ar...@gm...> wrote: > > Thanks, this was quite a tiny weekend project for you :) > I'll keep you tip in mind. > > Concerning the foreground/background issue: The problem here seems quite > random. It does not depend on the viewing angle. I rather just have to be > lucky everytime the plot command is executed. > If the plotting went right, I can rotate everything without any errors. > > I'm by no means a coder, but I find it hard to understand that executing > the > same script leads to a different outcome. My plan is to make a movie of the > cylinder while shrinking. If the problem would > just depend on the viewing angle, I would find a 'good angle', make it > constant and start the loop. But at the moment the outcome is just > arbitrary. > > Regards, > arsbbr > > arsbor, Actually, in your case, I think the issue was also caused by the bad array construction and plot_surface() was getting bad data depending on the strides. There is no random number generator in the code-path, so *something* must change. I noticed that it would happen as I changed the cstride/rstride values for the top cover (before I had fixed the top cover). If you still notice the issue now, let me know and I will look into it further, but it shouldn't be happening for you. Ben Root |
|
From: arsbbr <ar...@gm...> - 2010-07-25 22:43:42
|
Ben, your code fixed the shading problem, but it did not change anything on the clipping error. I also found that changing the cstride/rstride helps 'sometimes'. But also does changing the linewidth. The problem is consistency with my loop... I understand this is a bug that is not easy to fix. It would be totally sufficient for me if I could only find some parameters that'll always work. But this is not the case. Since there is no random procedure in the code there must be some footprint so that the starting parameters are not the same all the time. Maybe it is a memory thing and I have just to clear a cache/display buffer or something? Benjamin Root-2 wrote: > > > arsbor, > > Actually, in your case, I think the issue was also caused by the bad array > construction and plot_surface() was getting bad data depending on the > strides. There is no random number generator in the code-path, so > *something* must change. I noticed that it would happen as I changed the > cstride/rstride values for the top cover (before I had fixed the top > cover). If you still notice the issue now, let me know and I will look > into > it further, but it shouldn't be happening for you. > > Ben Root > > > > -- View this message in context: http://old.nabble.com/plot_surface-shading-and-clipping-error-tp29254649p29262268.html Sent from the matplotlib - users mailing list archive at Nabble.com. |