How can I add x and y ticks to my imagesc graph?

124 views (last 30 days)
I have the graph with the x and y data given in the files attached. These values vary in order of magnitude from 10^1 to 10^5, and 10^0 to 10^4 respectively. I have used centered ticks for imagesc graphs below, but for some reason with this data it just does not want to do it. The variable n for imagesc is also attached.
ax = gca;
ax.XTick = x;
ax.YTick = y;
ax.YDir = 'normal';
What I get is this:
Clearly, it does not even put all the ticks and the ticks are not even correct. The data x and y varies between said magnitude and each succesive element in their vectors jump by an order of magnitude less than the previous value, for example: 1e-1 2e-1 ... 9e-1 1e1 2e1 3e1 and so on. I've tried using pcolor instead to no avail.

Accepted Answer

Dave B
Dave B on 23 Nov 2021
Edited: Dave B on 23 Nov 2021
When you use image (or imagesc), the values in the matrix are distributed evenly. Changing the ticks just changes what's labels.
It sounds to me like pcolor is what you want. But you need to specify the x and y values when calling pcolor (and if you like, also) when specifying the ticks. Finally, you might consider a log scale for these data.
I've created all four combinations below (I set color limits just to make it easier to see)
caxis([0 100])
caxis([0 100])
set(gca,'XScale','log','YScale','log','CLim',[0 100])
caxis([0 100])
set(gca,'XScale','log','YScale','log','XTick',x,'YTick',y,'CLim',[0 100])
note that you can do 'shading flat' if you want to avoid all the lines:
set(gca,'XScale','log','YScale','log','XTick',x,'YTick',y,'CLim',[0 100])
shading flat
Alessandro Maria Laspina
Alessandro Maria Laspina on 23 Nov 2021
Edited: Alessandro Maria Laspina on 23 Nov 2021
Ill explain further why I want to this, perhaps there may be another solution. In short I want to extract multiple regions of interest (ROI) from the graph. These are fairly intuitive to notice when you have a scatter plot. Indeed, n, which I attached, is the result of collecting the total number of points in the respective x and y regions of a scatter plot. From here, I wanted to quantitatively describe where the ROI's are, in terms of cells of varying orders of magnitude. Maybe there are other ways I can do this without graphical means?
Dave B
Dave B on 24 Nov 2021
Edited: Dave B on 24 Nov 2021
When you set CLim to [0 100] it doesn't mean there are 100 colors. Instead, it means that values in your image data that are 100 or greater are mapped to the top of the colormap, values 0 or less are mapped to the bottom of the colormap, and values between 0 and 100 are mapped to the contents of the colormap. You might call this 'linear clamped'
patch([x flip(x)],[y flip(y)],[y flip(y)],'FaceColor','none','EDgeColor','interp','LineWidth',3)
colormap jet
yticklabels(["CLim(1) == 5" repelem("",numel(yticks)-2) "CLim(2) == 15"])
ylim padded
It sounds like your process sort-of recreated the work of binscatter, but with a nonlinear bin size. I would think that a log scale with some color limits would help, but I'm not sure what else to suggest that would help you accomplish your goal. You could transform the values in n however you want, but I'm not sure what nonlinearity would be helpful. You could even bin them as you binned the x and y values (choosing an order of magnitude binning scheme as you like) and then display those bins (if you go this route you could use discretize to transform n into a binned version of n)
load image_sc_eg.mat
edges=[0 logspace(1,5,10)];

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!