How to create a graph

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

 Respuesta aceptada

per isakson
per isakson el 1 de Oct. de 2012
Editada: per isakson el 31 de Oct. de 2012

0 votos

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 comentarios

Walter Roberson
Walter Roberson el 1 de Oct. de 2012
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.
John
John el 14 de Oct. de 2012
Editada: John el 14 de Oct. de 2012
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
Image Analyst
Image Analyst el 14 de Oct. de 2012
colormap(jet(256));
colorbar;
per isakson
per isakson el 14 de Oct. de 2012
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.
John
John el 15 de Oct. de 2012
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
per isakson
per isakson el 15 de Oct. de 2012
See above
John
John el 19 de Oct. de 2012
Editada: John el 21 de Oct. de 2012
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 el 31 de Oct. de 2012
See above

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 1 de Oct. de 2012

0 votos

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 comentario

John
John el 15 de Oct. de 2012
Editada: John el 15 de Oct. de 2012
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

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 1 de Oct. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by