Two-dimensional colormap

29 views (last 30 days)
Hello everyone,
I have the following arrays: spatial_grid(30001x1 elements), physical_time_elastic (2431x1 elements), and data_set_elastic (30001x4x2431 elements). What I want to is to plot a something like the figures that appears here: In my case, the x-th axis will be spatial_grid, the y-th axis the physical_time_elastic array, and the magnitude that will be encoded by colors will data_set_elastic (:,2,i), where i runs over the elements of physical_time_elastic (note that length(physical_time_elastic)=2431, as the number of elements of data_set_elastic in the third dimension). For each i, therefore, I have the value that corresponds to (spatial_grid, physical_time_elastic). What I have tried to do is the following, but it does not work:
for i=1:length(physical_time_elastic)
colormap jet;
axis xy;
xlabel('Track position, $x \, \, \left( \mu\mathrm{m} \right)$','FontSize',14,'interpreter','latex')
ylabel('Time, $t \, \, \left( \mathrm{ps} \right)$','FontSize',14,'interpreter','latex')
t1=title('Elastic scattering, $w_{1,2}=1/2$','FontSize',14,'interpreter','latex')
Any idea? I have attached a sample of what I get. The values that appears in the colorbar are completly wrong, because the variable that it is encoded in the color has values between -1 and +1. Also the track position begins in 0 and goes to a value like 3000, increasing its value linearly.

Accepted Answer

Joseph Cheng
Joseph Cheng on 20 Feb 2020
Edited: Joseph Cheng on 20 Feb 2020
I'm puzzeled by your first portion and the need for a for loop. unless you have a hold somewhere the images shouldn't be stacking and you're only doing it per item in physical_time_eleastic so you're imaging a single index at a time but without hold.... i'm not sure what is going on there.
for i=1:length(physical_time_elastic)
colormap jet;
in each loop you are imaging a 1x30001 image and overwriting it. as well as axes are not set correctly as your x and y do not match column row of data_set_elastic. so something else is going on there.
why don't you image the whole 2nd dimension?
here is dummy data
spatial_grid = [0:300]';
physical_time_elastic = [0:10:1000]';
data_set_elastic = 2*rand(301,3,101)-1;
% hold on
% for i=1:length(physical_time_elastic)
% image(spatial_grid.*(10^6),physical_time_elastic(i).*(10^(12)),data_set_elastic(:,2,i))
% end
colormap jet;
note squeezing data_set_elastic(:,2,:) which for you is (30001 x 1 x 2431 elements) would turn out to be (30001 x 2431 elements) which then doesn't match your 30001 for x (ie columns of the image) and 2431 for y. which is why there is a transpose of squeezing data_set_elastic(:,2,:)' .
also i'm not sure image deals with negative values which you should then use imagesc or other functions which you define the color scale.
Richard Wood
Richard Wood on 20 Feb 2020
I see your point about creating additional axis. The function caxis works as expected. Nothing more to ask, thank you very much for everything.

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!