How to create a graph

조회 수: 5 (최근 30일)
John
John 2012년 10월 1일
Hi,
Could somebody advise me on how you would produce a graph like this in matlab
Thank you
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 1일
plot a graph from what?

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

채택된 답변

per isakson
per isakson 2012년 10월 1일
편집: per isakson 2012년 10월 31일
My approach, which requires some work,
  • put data in a 2D array, C
  • plot with the function, image
  • Image type: Indexed (colormap)
  • Define a colormap, with a special slot, e.g. 1, for "missing data", white in your case. The length of the colormap = 64 is enough.
  • Map C carefully to the colormap, e.g. C(ii,jj)=1 for "missing data"
  • User defined tick-labels on the axes
  • and more
--- in response to comments I try to expand a bit ---
Variables
  • cmap is a colormap of size [64x3]. It associates the numbers [1,2,..., 64] to 64 different colors. (64 is an example.)
  • D is your 2D data array
  • C is an array of the same size as D. The values of C are integers in the interval, [1,64].
You create a suitable colormap, cmap, with the colormapeditor. You add some specific colors to signal special values of D, e.g. "missing data", outliers of various kinds etc.
You define a function, which takes D as input and returns C, e.g.
function C = D2C( D )
C = zeros( size(D) ); % zeros will cause error if not replaced
C( isnan(D) ) = 1; % nans will e displayed with color #1
C( D >= upper ) = 2; % values above upper gets color #2
C( D <= lower ) = 3; % values below lower gets color #3
etc.
any command is ok as long as the values of C are integers [1,64]
assert( not( any( C(:)==0 ) ), .... )
end
and to display the graph
colormap( cmap )
image( C )
.
--- in response to John's comment on 19 Oct 2012 at 16:45 ---
Here is a start to make a graph that resembles https://dl.dropbox.com/u/54057365/All/eff.JPG
%%Create some data
N = 1000;
Speed = transpose( logspace( 0, 2, N ) );
Acc = randn( N, 1 ) .* ( exp( - sqrt( 10*Speed/N ) ) );
Efficiency = ( Acc .* Speed );
nAccBins = 20; % Set resolution of image
nSpeedBins = 30;
Speed_upper = 100;
Speed_lower = 0;
Acc_upper = 3;
Acc_lower = -3;
ix_Speed = ceil( nSpeedBins * ( Speed - Speed_lower ) ...
/ ( Speed_upper - Speed_lower ) );
ix_Acc = ceil( nAccBins * ( Acc - Acc_lower ) ...
/ ( Acc_upper - Acc_lower ) );
M = accumarray( { ix_Speed, ix_Acc }, Efficiency, [], @mean, nan );
imh = imagesc( transpose( M ) );
axh = ancestor ( imh, 'Axes' );
set( axh, 'YDir', 'normal' )
Next step would be to map M to a special colormap with something like
C = D2C( M );
and display with
colormap( cmap )
image( C )
.
Backlog:
  • axis, ticks and ticklabels
  • colorbar
  댓글 수: 8
John
John 2012년 10월 19일
편집: John 2012년 10월 21일
Hello Per Isakson,
Thank you for your help with this. Would you mind if I asked you one further question please?
If I was trying to create a graph like this:
So I have 3 sets of data, acceleration, speed and efficiency.
For example Speed =40 and acceleration = 2 has an efficiency of 80%.
Would acceleration and speed be in the 2D array on their own? or would this become a 3D array with acceleration, speed and efficiency?
Thank you
John
per isakson
per isakson 2012년 10월 31일
See above

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

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 10월 1일
You would create an image - basically a 2D array. You must have that. If you don't have that, then you have nothing at all to display. Then display it with image() or imshow(), and apply a colormap. Not hard at all, assuming you have the data, temperature vs. current, in a 2D array already.
  댓글 수: 1
John
John 2012년 10월 15일
편집: John 2012년 10월 15일
Hello,
Thanks for your reply. I'm sorry but I don't understand how to get the colours to appear correctly.
This is what I am getting
but this is what I'm trying to achieve
Also how do you switch the axis?
Thank you for your help

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by