How to create a graph
4 次查看(过去 30 天)
显示 更早的评论
Hi,
Could somebody advise me on how you would produce a graph like this in matlab
Thank you
采纳的回答
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 ---
%%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 个评论
更多回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Green 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!