How to "imagesc" with logarithmic axis

196 ビュー (過去 30 日間)
Rebecca
Rebecca 2012 年 6 月 17 日
回答済み: Constantino 2018 年 11 月 2 日
Gurus,
I need to plot an image (named apple for example) with both x and y in logarithmic values. Below the the code example. It doesn't work....
*****************************************************************
x = 10.^linspace(log10(0.1),log10(3),10);
y = 10.^linspace(log10(1),log10(5),8);
apple = (y'*x/10);
imagesc(x,y,apple)
set(gca,'YScale','log','YMinorTick','on','Ydir','normal')
axis tight
set(gca,'XTick',([0.1,0.3, 1,3]))
set(gca,'YTick',([1 1.5 1.8 2.1 5]))
% codes below won't work, please help.!.
set(gca,'XScale','log')
set(gca,'XMinorTick','on')
set(gca,'YScale','log')
set(gca,'YMinorTick','on')
*****************************************************************
Best Regards,
Rebecca

回答 (5 件)

Walter Roberson
Walter Roberson 2012 年 6 月 18 日
Do you want the image to appear log-compressed, or do you want the image to look normal even though the axes are log scale?
The x and y coordinates you provide for imagesc() are data coordinates that are used to linearly interpolate pixel positions. You can use a large coordinate range, but it is going to use linear interpolation over whatever range you use. If you have a normal (linear) image and set the axes to log then the image will get log-compressed (if it is rendered at all.)
If you need a normal-looking image on an axes that is log scale, then the easiest way would be to put a second axes at the same location, with its Visible property set off, and put the normal image on that linear axes. But be careful with ginput() or datacursors possibly not having the value you expect when the cursor is over the linear image; it might be appropriate to turn the image hittest off.

Rebecca
Rebecca 2012 年 6 月 18 日
Walter,
Thank you for reply. I'm not sure of the meaning of "log compressed", or "look normal with log axes".
I want to make data analysis from the image. The data points are logarithmic linearly located along both x and y axis, i.e. 0.01, 0.1, 1, 10, ....So when the image is plotted with imagesc, data should be evenly distributed in the logarithmic arranged matrix. I am also interested in some special points, so xlabel and ylabel are set explicitly. I guess here a non-normal image is needed ^_^ The problem is x axes include fraction values, which invalidate the code "set(gca,'XScale','log')"
Based on my explanation, could you find a modified version to make it work?
Thank you so much! I've struggled with it for several days... Rebecca
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 18 日
I will have to experiment with this. Could you upload a copy of your image?
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers

サインインしてコメントする。


Paul
Paul 2013 年 5 月 23 日
Hey Rebecca, Ben figured this one out. -Paul

Constantino
Constantino 2018 年 11 月 2 日
I have a similar problem. Please realize i don't have an "image", but instead, I just want to make a quick image from a "rows x columns" matrix, where the Y axis must be plotted in log scale. I thought it would be simple, but it seems matlab has so much complexity that my approach is not working.
image(My2DMatrix,'CDataMapping','scaled')
works fine. I can change the color scale, axes ranges, and everything through the menus from the created image. However, transforming the image so it displays a log Y axis does nothing to the image. Pixels are still squares of equal size (I think that is the key around my issue). Maybe I need another type of plot? I'm a complete newbe in matlab. Have worked with other languages but it seems matlab is not so easy as other programming environments.
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 11 月 2 日
Try warp()
However nothing can change the fact that pixels in the display are rectangular, so if you have a wide range of data, the pixels more towards 0 are going to be overrepresented on the display.

サインインしてコメントする。


Constantino
Constantino 2018 年 11 月 2 日
Ok, I solved my problem using contourf, which handles better my type of data

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by