How to "imagesc" with logarithmic axis
218 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(5 个)
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.
0 个评论
Rebecca
2012-6-18
1 个评论
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
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
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
2018-11-2
Ok, I solved my problem using contourf, which handles better my type of data
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!