I do not understand how plot_surface and np.mgrid work together to create a face.
When I try I keep getting 3 faces in the shape of a 'Z'. I would like to see a proper example of a cube to understand this better.
Related
I have generated a series of 2D plots using matplotlib.pyplot. I want to change the perspective of each 2D plot to make them look more "3D" (from the rectangular shape to parallelogram shape) and stack them together by hand, which will look something like this:
If there are texts present in the 2D plot (e.g. labels, title, legend), I want them to be rotated together with the plot. The reason I don't want to use mplot3d is that it doesn't support some advanced functions that is used in my 2D plots.
This has already been asked before for 3D plots: how to set "camera position" for 3d plots using python/matplotlib?, but the ax.view_init is only implemented for 3D plots. I wonder if there is a way to also change the camera angle for a 2D plot. If not, are there any tools that can do this task?
Currently, I am attempting to plot some "bubble" like shapes in a 3D space using Mayavi/Mlab. These bubbles are represented by a numpy array of shape (840,1100,30) where the parameters represent (x,y,z) and the value at any x,y,z is either 1 or 0. The array can be thought of as a collection of Voxels that are either on or off. I try to plot this data with the following commands:
mlab.contour3d(finalVolume)
mlab.show()
But the plot is coming out in 2 dimensions instead of in 3 dimensions. I have looked at the documentation but am having trouble understanding. If anyone could provide some help or a push in the right direction, then I would be very appreciative!
Thanks!
Sounds like you need to use volume rendering to accomplish this. This can be accomplished using:
mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8)
You will need to adjust the opacity transfer function using vmin and vmax to make an appropriate image. Examples on volume rendering can be found at: http://docs.enthought.com/mayavi/mayavi/mlab.html
Is there any kind of chance to "cut" the surface plot (x,y,z) made by use of the matplotlib by some well defined boundaries, so that I can draw any kind of shape in 3D. Now I can do that but x,y are 2D arrays (meshgrid) and the shape is always rectangular.
Example:
Here, the plate has a base-shape of rectangular (2d-array are used). The z coordinates are derived by some function f=f(x,y).
What I would like achieve is shown in the picture below (made by hand ;)). One idea is to turn-off a single cell. But how to make the cells transparent?
What you'd like is to mask some regions in the surface. Unfortunately, matplotlib does not support masked arrays yet for plot_surface, but you could circumvent it by using np.nan for those masked regions.
It is also detailed in plotting-a-masked-surface-plot-using-python-numpy-and-matplotlib.
I am attempting to do something similar to this:
sample ozone profile
Not necessarily over an orthographic projection - a cube over a map would suffice.
I'm able to plot the PolyCollection object produced by matplotlib.pyplot.pcolor, but cannot figure out if there's an accepted way of plotting the profile over an arbitrary lat/lon path.
The only thing I can think of right now is continuing to use pcolor() to get the face colors, then just modifying the vertices for each Poly object.
If you want to create a 3D projection, then you may use the plot_surface. It essentially draws a 2D array where the 3D coordinates of each vertex is given.
You might get some ideas by looking at this: Creating intersecting images in matplotlib with imshow or other function
The matplotlib solution there is essentially the same as using pcolor, but the 3D arithmetics is carried out by matplotlib. The suggestion to use mayavi is also something worth conisdering, as matplotlib is not at its strongest with 3D projected raster data.
I am near my wits end with this problem. Please bear with me as I try to explain my problem. I have a 3D model with a triangulated surface. I then need to add some data (in the form of colour) to the surface of the 3D model. It should resemble something shown in this figure: http://user.cscs.ch/fileadmin/user_upload/customers/users_entry_point/pictures/Visualization/Gallery/Cardiac_Therapy.png.
My problem is that I don't really know how to interpolate data over a triangulated surface. I was wondering if someone might have an idea or possible point me in the right direction.
I should mention that I am using python and mayavi but I am also willing to work with MATLAB.
Matlab's trisurf may work for you. You give it (x,y,z) coordinates and a color for each vertex.