|
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 |