How to plot contourf plot on one side of surf plot?

I saw a plot in the journal that I want to replicate in Matlab (the original plot is done by Python, I think). The plot shows a 2D wavy interace with 2D velocity profile on the sides of the plot. In Matlab, I can use surf to create 2D wave interace as a function of x and y where the height is in z. However, I am not sure how I could plot these 2D velocity profile in x-z or y-z plane. If just use contourf to plot it, it will plot on the x-y axis as default. Therefore I am wondering whether it is possible to plot contourf on select axis with the surf plot? Thank you!

9 comentarios

Is the image above an example of what you want? The image does not look like your description of what you want. Perhaps I don't understand what you want.
If you have arrays X, Y, and Z(X,Y), then what do you want to plot on the x-z plane or on the y-z plane?
Here is an example of a 3D scatter plot with the marginal probability density (i.e. histogram) projected onto one side. Source. Is this what you want?
The example below (https://www.sciencedirect.com/science/article/pii/S0165027004004418) is a plot of the time-dependent fourier transform, where the signal anmplitude versus time is also plotted on one side. You can imagine plotting the TDFT as a 3D surface, and plotting the amplitude versus time on one "wall", and plotting the 1D FFT on the other "wall". Plot below illustrates this concept (using only the TDFT and the amplitude versus time plot) but it does not use 3D plotting. Is this what you want, but you want it in 3D?
Please supply an example image and the journal source for it, and supply some sample data. Thank you.
Thank you for your quick reply! Sorry that I didn't make myself clear. The first example figure that you showed, where it has 3D scatter with a probability density function on the side is almost what I want, except that I want a surf plot (which resembles the gray interface in the figure that I show earlier) to replace the 3D scatter, and a 2D contourf plot projected on one side to replace the probability curve.
To be specific, I have attached a sample dataset for you to take a look. Now I have a function eta(x,y) that I want to plot as surf. In my dataset, you can just do
load('data_3D_2D.mat')
figure
surf(xx_eta,yy_eta,eta)
Then, on the surf plot, where eta is plotted in z, I want to plot a contourf plot of velocity u(x,z) in the x-z side on the wall, you can do
figure
contourf(xx_u,zz_u,u)
Then I want to combine these two plots just like the first one that you have shown. Thank you so much for your help!
Best,
Jinshi
It's not possible to do that with the builtin MATLAB countourf function, no.
Note that the plots @William Rose is showing were built using
import numpy as np
import plotly.plotly as py
and so were drawn with it, not with base MATLAB handle graphics functions.
One could paint pixels in the proper locations to appear as desired in MATLAB-only code, but one would have to do all the orthographic projection calculations explicitly in order to do so. It simply isn't possible to rotate the plane of any of the builtin 3D functions; they are all of the z=f(x,y) functional form and that is invariant(*).
(*) Well, I suppose one could add a second to the original axes and then figure out how to mung on the X-, Y-, CData arrays. I've made no efforts along that line as to feasibility.
Jinshi
Jinshi el 12 de Nov. de 2025
Hi @dpb,
Thank you for your reply. Yeah I realized that the example that @William Rose gave is in Python. I believe the original plot that I show is also done in Python. I will checkout and see whether I can get the desired plot this way using numpy and plotly. Thank you!
Best,
Jinshi
DGM
DGM el 12 de Nov. de 2025
Editada: DGM el 12 de Nov. de 2025
Do you actually want a contour plot? What's shown is a pcolor plot. If you don't need discrete contour levels, then a pseudocolor image oriented outside the xy plane can either be done with pcolor() and some object manipulation, or it can be done using surf() and appropriate input ordering.
I don't know of a way to make it work with contourf(), though I vaguely remember going down this road before.
Jinshi
Jinshi el 12 de Nov. de 2025
Hi @DGM, no I don't really need a contour plot with discrete contour levels. All I need for that x-z plane 2D plot is to show the trend of the velocities at each locations. Therefore I don't mind using other plot functions.
Could you enlignten me with how to do it using pcolor? I am not sure whether changing the variable order of surf() would work, since I'd like to plot a x-z plane 2D plot, and also another y-z plane 2D plot with the surf plot that I show.
Thank you!
Best,
Jinshi
DGM
DGM el 12 de Nov. de 2025
I had a half-baked generic example put together, but give me a bit and I'll see if I can adapt it to your data. That way I don't set you up for a problem I didn't expect.
Jinshi
Jinshi el 12 de Nov. de 2025
Wow @DGM this is exactly what I need! What a clever way to solve my question. The colormap is not a problem (yet) since there is no colormap on eta and the colormap for my x-z and y-z plot should be the same. I'd like to accept your answer but it seems that you put this in the comment section rather than the answer section... Please let me know how to accept your answer and I am more than happy to do that!
Best,
Jinshi
DGM
DGM el 12 de Nov. de 2025
I just moved it to an answer.

Iniciar sesión para comentar.

 Respuesta aceptada

DGM
DGM el 12 de Nov. de 2025
Movida: DGM el 12 de Nov. de 2025
This is a start.
load data_3D_2D.mat
surf(xx_eta,yy_eta,eta,'edgecolor','none');
hold on; grid on; axis equal
yy_u = max(yy_eta(:))*ones(size(xx_u)); % constant y-data at the edge of the plot
surf(xx_u,yy_u,zz_u,u,'edgecolor','none','facelighting','none');
Depending on your expectations, it might need to get more complicated. One potential issue is that both of these objects use the same colormap and color scaling (i.e. clim()). Since an axes has one set of color mapping properties, if you wanted to use different colormaps or color scales, the way around that is to use multiple overlaid axes.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Etiquetas

Preguntada:

el 11 de Nov. de 2025

Comentada:

el 13 de Nov. de 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by