How to get specific tick axis values equally spaced, independently of their values?

6 views (last 30 days)
I have got the following code to create a 2D colour map of the quantity ref_n_order , depending on the Frequency and on the Solid Content.
I want to plot a map with 6 rows (Solid Content) and 40 columns (Frequency) with the map displaying a colour array for the intensity of the ref_n_order values. The ref_n_order and the Frequency file have been uploaded, in case it helps.
load ref_n_order.mat
load freq.mat
perc(:,1) = [17.67 , 8.39, 2.46, 0.92, 0.23, 0.12]; %y-axis arranged in decreasing order, this is the Solid Content
%the x-axis consists on a 1 x 40 data array
%the color map consists of 6 x 40 data array, ref_n_order
figure(4)
imagesc(freq, perc(:,1), ref_n_order)
c = colorbar;
c.Label.String = 'n';
caxis([min(min(ref_n_order)) max(max(ref_n_order))])
xlabel('Solid Content (%)')
ylabel('Frequency (THz)')
Unfortunately, the image I obtain (uploaded below), has the Frequency on the y-axis and the Solid Contents on the x-axis.
Another big problem with the image is how the ref_n_order color matrix rows seems to be inverted, row 1,2,3,4,5,6,of the data matrix are instead plotted as 6,5,4,3,2,1 . 6 being the top row of the image, and 1 being the bottom row, not corresponding to the correct Solid Content.
Thanks for your help.

Answers (2)

Mathieu NOE
Mathieu NOE on 4 May 2023
hello
1/ seems to me you simply mixed x and ylabels
2/ you may want the Y dir to be put back in "normal" mode
result obtained with these two simple mods :
code
perc(:,1) = [17.67 , 8.39, 2.46, 0.92, 0.23, 0.12]; %y-axis arranged in decreasing order, this is the Solid Content
%the x-axis consists on a 1 x 40 data array
%the color map consists of 6 x 40 data array, ref_n_order
figure(4)
imagesc(freq, perc(:,1), ref_n_order)
set(gca,'YDir','normal') % put back y direction as usual
c = colorbar
c.Label.String = 'n';
caxis([min(min(ref_n_order)) max(max(ref_n_order))])
ylabel('Solid Content (%)')
xlabel('Frequency (THz)')
now I am not sure you also want to invert the row order of your data
you can do it with flipud
perc(:,1) = [17.67 , 8.39, 2.46, 0.92, 0.23, 0.12]; %y-axis arranged in decreasing order, this is the Solid Content
%the x-axis consists on a 1 x 40 data array
%the color map consists of 6 x 40 data array, ref_n_order
figure(4)
imagesc(freq, perc(:,1), flipud(ref_n_order))
set(gca,'YDir','normal') % put back y direction as usual
c = colorbar
c.Label.String = 'n';
caxis([min(min(ref_n_order)) max(max(ref_n_order))])
ylabel('Solid Content (%)')
xlabel('Frequency (THz)')

Cris LaPierre
Cris LaPierre on 4 May 2023
You have created your image using this format:
In an image, the rows of your matrix correspond to y, and the columns to x. Note that the (0,0) in an image is the top left corner. Also note that x and y should either be scalars, or 2 element vectors. If you pass in a vector of numbers, it uses the bounds to create evenly spaced ticks between them.
You plot a 6x40, so there are 6 steps on your y axis, and 40 on your x. The ticks are spread out evenly over these values. The values of your ticks come from freq (on x), and perc(:,1) on y. The only thing I see is that your code labels your Y axis as Frequency, and X axis as Solid Content:
xlabel('Solid Content (%)')
ylabel('Frequency (THz)')
Flip those, and you should have what you want.
If you want (0,0) to be the bottom left (perhaps why you think you color matrix is inverted), use axis xy.
load ref_n_order.mat
load freq.mat
perc(:,1) = [17.67 , 8.39, 2.46, 0.92, 0.23, 0.12]; %y-axis arranged in decreasing order, this is the Solid Content
%the x-axis consists on a 1 x 40 data array
%the color map consists of 6 x 40 data array, ref_n_order
[mnf,mxf] = bounds(freq)
mnf = 0
mxf = 0.9922
[mnp,mxp] = bounds(perc(:,1))
mnp = 0.1200
mxp = 17.6700
imagesc(freq, perc(:,1), ref_n_order)
c = colorbar;
c.Label.String = 'n';
caxis([min(min(ref_n_order)) max(max(ref_n_order))])
ylabel('Solid Content (%)')
xlabel('Frequency (THz)')
axis xy
  2 Comments
Cris LaPierre
Cris LaPierre on 4 May 2023
Perhaps this is more along the lines of what you want?
load ref_n_order.mat
load freq.mat
perc = [17.67 , 8.39, 2.46, 0.92, 0.23, 0.12]; %y-axis arranged in decreasing order, this is the Solid Content
%the x-axis consists on a 1 x 40 data array
%the color map consists of 6 x 40 data array, ref_n_order
imagesc(freq([1 end]), [], ref_n_order)
yticklabels(perc)
c = colorbar;
c.Label.String = 'n';
caxis([min(min(ref_n_order)) max(max(ref_n_order))])
ylabel('Solid Content (%)')
xlabel('Frequency (THz)')
axis xy

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!