How to create a graph

Hi,
Could somebody advise me on how you would produce a graph like this in matlab
Thank you

 采纳的回答

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 个评论

Alternately instead of using a special color index for the missing data, set the AlphaData for those pixels to 0 so that the background shows through.
Hello,
Thank you for your replies above. I've put the data in a 2D array (called C) and plotted the image using
image(C)
Could you demonstrate how I would create a colour map and map C onto it?
My apologies if this is a basic question.
Many thanks for your help
John
colormap(jet(256));
colorbar;
To make a colormap:
  1. use the colormapeditor that comes with Matlab. Output: a [64x3 double] array och RGB-values
  2. use a text editor to modify special entries if necessary. However, everthing can be done with the colormap editor.
Mapping the data values to the interval, [1,64], requires some code.
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
See above
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
See above

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2012-10-1

0 个投票

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

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Red 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by