How to create a graph with X, Y + Contour Axes.

Hello, I need some guidance for creating a very similar chart shown below in the link.
For each axis, including the contoured one, I also have some data between 0-1 (actally % values) of corresponding type and I am supposed to show them in a single chart. I am not sure about how to combine those different values into one. If someone can offer some guidance with key functions, I would be greatly faithful.
Thanks in advance.

 채택된 답변

the cyclist
the cyclist 2012년 2월 20일

0 개 추천

Here is a simple example, which I hope you can bend to your needs. I adapted it from the documentation here: http://www.mathworks.com/help/techdoc/ref/contour.html. I think it illustrates most of what you want, including how to overlay multiple plots (with the hold command), adding labels to the contours, etc. There are help files for all the different functions I used, of course.
figure
hold on
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2);
[C,h] = contour(X,Y,Z);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)
addedRandomX = rand(1,20);
addedRandomY = rand(1,20);
plot(addedRandomX, 1+addedRandomY,'kx')
plot(-addedRandomX,1+addedRandomY,'ro')

댓글 수: 5

Al Onen
Al Onen 2012년 2월 25일
Hello, I couldnt find time to work on this earlier, but I'm still stuck. It turned out to be the main function of contour lines is Z = (1/((1/(1-Y))+(1/X)-1)), and it's not applicable when X or Y are equal to 1 or 0, so that's why contour lines are between 0.1 and 0.9 on the linked chart and can't use Z as a single variable on code because of not fitting matrix dimensions with X and Y matrices. I also tried to plot contours individually, but failed. I'm not good at Matlab and definitely doing something wrong; so if you could spare few more moments to help, i would be more faithful :)
the cyclist
the cyclist 2012년 2월 25일
Can you post your code and explain in more detail what is wrong? Is the code producing an error, or just results that you don't expect?
Al Onen
Al Onen 2012년 2월 26일
Firstly I tried
figure
hold on
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = (1/((1/(1-Y))+(1/X)-1));
[C,h] = contour(X,Y,Z);
...
But Matlab gave an Matrix dimensions error;
??? Error using ==> mldivide
Matrix dimensions must agree.
Error in ==> cont at 5
Z = (1/((1/(1-Y))+(1/X)-1));
I also tried to create a loop to bypass invalid intervals for Z (X and/or Y = 1 and 0), but couldn't manage to create proper codes.
Lastly, I created the mesh for X & Y for desired intervals, and try to implement curves of Z individually with fplot function, and but since my Z function is 2-variable dependent, I couldnt manage the run the code as well logically.
Just had a thought, Should I try plotting them with some differential equation approach?
Sorry for being a headache by the way :)
the cyclist
the cyclist 2012년 2월 26일
The reason you got the mldivide error when calculating Z is that you were using the syntax for matrix division, where you actually wanted element-by-element division.
Try this instead:
figure
hold on
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = 1./((1./(1-Y))+(1./X)-1);
[C,h] = contour(X,Y,Z)
Notice that I added "./" in place of just "/". The dots are the syntax for element-by-element operations.
I'm not sure if the result is what you expect, but at least it executes.
Al Onen
Al Onen 2012년 2월 26일
Thank you so much. Indeed it works - I'm such a loser with Matlab. :) I have to keep the purpose of dots in mind. Now the answer is officially accepted.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Al Onen
Al Onen 2012년 2월 21일

0 개 추천

Thank you, that will probably do the trick.

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2012년 2월 20일

편집:

2013년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by