MATLAB Answers

How Do I Get xticklabels to Scale Properly When Zooming on an Imagesc Plot?

6 views (last 30 days)
Sean
Sean on 11 Dec 2012
Answered: Pratik Mahamuni on 22 Nov 2019
Hi,
I'm using imagesc to display some values in a GUI window. There are three subplots that use imagesc. I want to use the values in g_spectrum.aspectDeg for the xTickLabels. They are just a series of angles in degrees. However, when I try
set(gca, 'xTickLabel', num2str(g_spectrum.aspectDeg));
the xTickLabels that are displayed are the first 8 values (I only have 8 xticks on each imagesc plot). What I need the code to do is to scale the xTickLabels approprietly for the level of zoom on the plot.
i.e. in the case where it is completely "zoomed out", instead of displaying the first 8 labels, I'd like it to display 8 values over the range of the labels (in this case it should be from 337.718 to 176.23). Then, if I zoom in on some values in middle, it might display 257.022 to 256.526).
Here is the code used to display the images.
ha(1)=subplot('Position',[ 0.05 0.66 0.9 0.29]);
imagesc(aspect, yval, ChatCpi,[0 1]);colormap(summer)
axis([-Inf Inf -Inf Inf]);
set(gca,'ytick',1:NumFreq);
set(gca,'yTickLabel',freqstring);
set(gca, 'xTickLabel', num2str(g_spectrum.aspectDeg));
title(title1,'fontsize',12,'fontweight','b');
ha(2)= subplot('Position',[ 0.05 0.37 0.9 0.29]);
imagesc(xval, yval',JemOnly,[0 1]);colormap(summer)
axis([-Inf Inf -Inf Inf]);
set(gca,'ytick',1:NumFreq);
set(gca,'yTickLabel',freqstring);
set(gca, 'xTickLabel', num2str(g_spectrum.aspectDeg));
ha(3)=subplot('Position',[ 0.05 0.08 0.9 0.29]);
imagesc(xval, yval,JemChat,[0 1]);colormap(summer)
xlabel('Aspect(deg)');
axis([-Inf Inf -Inf Inf]);
set(gca,'ytick',1:NumFreq);
set(gca,'yTickLabel',freqstring);
set(gca, 'xTickLabel', num2str(g_spectrum.aspectDeg));

  0 Comments

Sign in to comment.

Answers (1)

Pratik Mahamuni
Pratik Mahamuni on 22 Nov 2019
Sean,
You could try this function Dynamic Date Ticks; you may have to play around it a little bit considering the function is written for dates. But a similar concept can be used for other XTicks.

  0 Comments

Sign in to comment.

Sign in to answer this question.