Clear Filters
Clear Filters

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

9 views (last 30 days)
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));

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.

Products

Community Treasure Hunt

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

Start Hunting!