logarithmic range colorbar imagesc
조회 수: 57 (최근 30일)
In my code I use the function imagesc; plotting (X,Y,Z) data in which: X vector distance, Y vector time, and my data Z = Z(X,Y) a matrix. In my plot the 80% of the image has one color, because the change of Z data occurred only in a specific area of X-Y. I need to change the colorbar range, from a normal to a logarithmic one, to improve visual the range of the change of my output data through time along the distance X. Please, if anyone knows how to solve this issue let me know.
Kelly Kearney 2015년 11월 9일
You can use my cptcmap.m function to create a logarithmically-spaced colormap (and corresponding colorbar).
However, keep in mind that Matlab requires linearly-spaced color intervals in its colormaps, so my function achieves uneven color intervals by replicating certain colors many times. You may not get the results you want if your values span too many orders of magnitude. For example, to create a colormap where one color spans only 1/1000th of the color range, you need a 1000-color colormap. I believe some systems (Windows?) may limit you to 256 colors in a colormap.
However, if your values span a relatively small range, the following example should work:
x = peaks(200);
x = (x - min(x(:)))./(max(x(:))-min(x(:)));
x = x*9 + 1;
tk = logspace(0,1,10);
cmap = jet(9);
ctable = [tk(1:end-1)' cmap*255 tk(2:end)' cmap*255];
save mycol.cpt ctable -ascii;
ax = axes;
cptcmap('mycol', 'mapping', 'direct');
cptcbar(gca, 'mycol', 'eastoutside', false);
Image Analyst 2015년 11월 9일
Use caxis() to specify what image values the colorbar should start at and stop at.
Adam 2015년 11월 9일
편집: Adam 님. 2015년 11월 9일
I would normally solve this problem simply by taking the logarithm of my data and plotting that if simply constraining the colourbar range is not enough.
I'm not sure there is a simply way to show a non-linear colourmap without creating your own colourmap. The mapping is always linear as far as I am aware which would imply you can either make your data logarithmic or you can define a logarithmic colourmap yourself. I don't know how to do the latter off-hand though.