How to plot 4D contourf for the matrix C(40*40) with respect to A(40*40) as x axis and B(40*40) as y axis for different levels z=1000, 800, 600, 400 in one plot?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Dear Sir I have three matrices A,B and C having same size 40*40. I want to plot a contour of C(40*40) taking A(40*40) as x axis and B(40*40) as y axis for different levels z=1000, 800, 600, 400 in one plot. Please help.
Accepted Answer
Walter Roberson
on 19 Sep 2015
If your X and Y data are sorted in a good grid, then
contourf(X, Y, C, [400, 600, 800, 1000])
If your X and Y are not sortable to a good grid then you will need to do some grid interpolation and contour that.
11 Comments
Actually I have three matrices X1, Y1, C1 for z=400, X2, Y2, C2 for z=600, X3, Y3, C3 for z=800, X4, Y4, C4 for z=1000 and i want to plot contourf (x, y, c) for each value of z in one plot...please help
contourf(X1, Y1, C1, [400 400]);
hold on
contourf(X2, Y2, C2, [600 600]);
contourf(X3, Y3, C3, [800 800]);
contourf(X4, Y4, C4, [1000 1000]);
hold off
The duplication of the Z value is needed to distinguish from the case of asking for 400 or 600 or 800 or 1000 contour levels to be automatically generated.
I dont know why the above code is not working for me.. Only blank image is coming..but contourf(X1, Y1, C1)is working for indivisual plot without level. Actually i need the plot like this
Thanks a lot for helping me
contour3(X1, Y1, 400*ones(size(X1)), C1, 'filled','on');
hold on
contour3(X2, Y2, 600*ones(size(X2)), C2, 'filled','on');
contour3(X3, Y3, 800*ones(size(X3)), C3, 'filled','on');
contour3(X4, Y4, 1000*ones(size(X4)), C4, 'filled','on');
still the following error is coming
Error using contour3 (line 79)
Invalid LineSpec string.
z is basically atmospheric pressure level....for each pressue level we want to show the contourf plots for three variables...thanks
This is basically four 2d plots presenting in the third direction in a single figure....
Which MATLAB version are you using? The representation of contour plots changed as of R2014b.
Thank you sir for your response... I am using R2013a
This was tricky to figure out.
I have enclosed a file patchfill.m which can be used for this purpose. This is for HG1 (Handle Graphics 1) only in its present form (I do not have an HG2 version to experiment with.) Beware: R2014b and later (HG2) represent contours a different way!
[~, h] = contour3(X1, Y1, C1);
hold on
patchfill(h, 400);
[~, h] = contour3(X2, Y2, C2);
patchfill(h, 600);
[~, h] = contour3(X3, Y3, C3);
patchfill(h, 800);
[~, h] = contour3(X4, Y4, C4);
patchfill(h, 1000);
The patchfill routine I provide does two things:
- alters the patch() properties returned by contour3 to allow the contours to fill. The contours returned by contour3 (in HG1) are deliberately configured to make it hard to turn on filling.
- sets the Z values to the value passed in, if one is passed in.
Thanks a lot :)
More Answers (0)
Categories
Find more on Contour Plots in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)