ShowText for 2d plot or Converting plot to contour

조회 수: 4 (최근 30일)
Babak Ravaji
Babak Ravaji 2019년 1월 23일
답변: Markus Klemm 2019년 3월 14일
In order to take advantage of contour capability of "ShowText", I want to convert my 2d plot into a contour and then show a value on the curve. Anyone can help on converting 2d plot to contour or any better suggestion to show a specific value on the curve nicely like following?
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 24일
What is the input to this? Is it an axes that has some lines drawn on it, and the task requires extracting data from the lines and somehow building a matrix suitable for use with contour()?

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

답변 (3개)

Babak Ravaji
Babak Ravaji 2019년 1월 24일
The input is simply some curves in the X-Y plane. for example it is:
X Y
0 0
0.1 1
0.2 2
0.3 1.5
0.4 4
or any other plots in the X-Y plane.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 24일
Is the input the data that defines the curves, or is the input the already-drawn curves?
Is there a constant z coordinate associated with each curve?
Is the real question here how to label a curve in the middle of the curve? If so then is the line-gap-label-gap-line required or could it be label just off of the curve?

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


Babak Ravaji
Babak Ravaji 2019년 1월 25일
Input data that define the curves is available.
Yes there is a constant z associated to each curve.
You are right, the real question is how to lable a curve in the middle of the curve. Yes the line-gap-label-gap-line is required.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 25일
I do not see any MATLAB routine for that purpose, and I do not notice anything in the File Exchange either.
You could write a function for it that chose a location near the midpoint of the curve, and introduced artificial stopping in it, [X(1:n), X_before_gap, nan, X_after_gap, X(n+1:end)] and likewise for Y, and then text() into the gap.

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


Markus Klemm
Markus Klemm 2019년 3월 14일
Hi,
I just had the same problem and wrote a small, straight forward function, which works for me.
Maybe it can serve someone else as well?
% inp_x: 1xM-vector with x-coordinates
% inp_z: 1xN-vector with z-coordinates (the 'text-Info')
% inp_y: MxN-matrix with datapoints
function c=plotPseudoContour(inp_x,inp_z,inp_y)
x=linspace(min(inp_x),max(inp_x),500);
y=linspace(min(inp_z),max(inp_z),500);
[X,Y]=meshgrid(x,y);
[X_inp,Y_inp]=meshgrid(inp_x,inp_z);
Z=interp2(X_inp,Y_inp,inp_y',X,Y);
c=contour(X,Z,Y,inp_z,'ShowText','on');

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by