How can I create a segmented contour plot?

I solved a 1D moving boundary heat transfer problem and I want to recreate something like the graphs on the left in this image. Anyone know how I can do that?

2 个评论

The left graphs are not good in my opinion. They should not have smooth colorbars, falsely indicating step-wise changes in temperature.
What type of data do you have? Did you try contourf?
Hey thanks for your help!
Well it's a 1d ice cube, so I solved for the temperature at each discretization point
---------Temp ---------Temp ---------Temp ---------Temp
and so on. I tried contourf and got something that didn't make sense but I also don't use it very much so maybe I didn't know how to plot it properly?
Say at time step 1: I have 5 temperatures which I solved for in addition to the temperatures on the boundaries. I also have their positions in the x-axis. So what I did is I concatenated those vectors and did contourf on that but it didn't work :/
Z = [temps positions] contourf(Z)
I have attached what I got.

请先登录,再进行评论。

 采纳的回答

Looks like you actually have a 2D data set but want to plot in 3D, which means you have to add an arbitrary 'depth'. This will give you a color-figure that is more difficult to interpret than a normal 2D-plot. Nevertheless, I've made a small example, with result attached.
%%Create data
x=0:180;
z=-sind(x);
figure;
subplot(1,3,1)
plot(x,z)
axis tight
%%Extrude to a width of 10 and plot
subplot(1,3,2)
y=1:10;
z2=repmat(z,numel(y),1);
contourf(x,y,z2)
subplot(1,3,3)
surf(x,y,z2,'edgecolor','none')
colorbar
Note: Surf and contourf will connect the data linearly. If you want a more correct shape of the temperature distribution, then you have to either solve for more points or apply another interpolation method prior to plotting (using e.g. meshgrid & griddata).

1 个评论

Thanks Jonas. I'll try this as well.
I actually did try the meshgrid method last night and because I don't entirely understand it, I ended up playing around with the inputs to that and contourf and finally was able to get the plot I wanted by making sure that the Z matrix was just a repeat of the temperature data.
I'll have to study those two functions to actually understand why that worked. I'll also try your method.
Thanks again for your help!!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by