matplotlib surface plot limited by the boundaries - python

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.

Related

How to set camera angle of a 2D plot in matplotlib?

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?

How to make a contour plot with three variables in a dataset?

I am trying to generate a contour graph in terms of three parameters (say x, y, z). These parameters come from a data table of more than 5000 values.I need the graphics to look like the figures shown below.
Contour plots are most easily made using matplotlib's contour.
There's also a corresponding contourf function that provides filled contours. Anyway, what you uploaded looks more like matplotlib's pcolor or pcolormesh, as they draw colored pixels instead of isovalue lines.
Here's a nice comparison of both if you need to choose.
Edit: For (x,y,z) points that are not distributed on a grid (i.e. come from random samples), a working solution seems to be a combination of binned_statistic_2d and then either plt.pcolor or plt.contour.

Matplotlib: Using np.mgrid to create a cube surface plot

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.

plotting 2D slice of arbitrary orientation through 3D data in matplotlib

I have a 3D regular grid of data. I would like to write a routine allowing the user to specify a plane slicing through the data with arbitrary orientation and returning a contour plot of the data in the plane. Is there a ready-made way in matplotlib to do this? Could find anything in the docs.
You can use roll function of numpy to rotate your plane and make it parallel with a base plane. now you can choose your plane and plot. Only problem is that at close to edges the value from one side will be added to opposite side.

Plotting 2D satellite profile data in 3D over earth projection in Python

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.

Categories

Resources