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

104 次查看(过去 30 天)
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.
imagesc(n)
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.

采纳的回答

Dave B
Dave B 2021-11-23
编辑:Dave B 2021-11-23
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)
load('image_sc_eg.mat')
pcolor(x,y,n);
caxis([0 100])
pcolor(x,y,n)
xticks(x)
yticks(y)
caxis([0 100])
pcolor(x,y,n)
set(gca,'XScale','log','YScale','log','CLim',[0 100])
caxis([0 100])
pcolor(x,y,n)
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:
pcolor(x,y,n)
set(gca,'XScale','log','YScale','log','XTick',x,'YTick',y,'CLim',[0 100])
shading flat
  10 个评论
Alessandro Maria Laspina
编辑:Alessandro Maria Laspina 2021-11-23
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 2021-11-24
编辑:Dave B 2021-11-24
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'
x=linspace(-50,200,100);
y=max(min(x,90),10);
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)];
nb=discretize(n,edges);
imagesc(nb);
c=colorbar;
c.Ticks=1.5:9.5;
bincenters=edges(1:end-1)+diff(edges)/2;
c.TickLabels=bincenters;
colormap(hot(9))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by