Effacer les filtres
Effacer les filtres

Colormap a plot based on value of (x,y)

15 vues (au cours des 30 derniers jours)
Matthew
Matthew le 16 Juin 2024
Réponse apportée : Manikanta Aditya le 3 Juil 2024 à 6:11
Hello,
I have a table T of dimensions x,y where each point has a value between -100 and 100.
I want to graph this data such that T(1,1) is point 1,1 on the graph and the color of that point is determined by the value of T(1,1)
I included a picture of something similar to what I want my plot to look like, along with some code that generates an example table for graphing
Thanks in advance for any help you can provide.
clear
clc
close all
%This will generate a table with example data.
x=100
y=50
data=zeros(y,x);
data(1,1)=50;
dchartdx=25/x;
dchartdy=25/y;
for ii=1:x
data(1,ii+1)=data(1,ii)+dchartdx;
end
for ii=1:x+1
for ij=1:y
data(ij+1,ii)=data(ij,ii)+dchartdy;
end
end
  1 commentaire
DGM
DGM le 16 Juin 2024
Try imagesc(). If you want explicit control over the colormap limits, use clim().
imagesc(data) % display the data with the colormap ends corresponding to the data extrema
colorbar % add a colorbar
colormap(jet(256)) % specify a colormap

Connectez-vous pour commenter.

Réponses (1)

Manikanta Aditya
Manikanta Aditya le 3 Juil 2024 à 6:11
Hi,
The image you've provided shows a depth vs range plot, likely representing some kind of acoustic or seismic data.
To create a similar plot using MATLAB with your data, you can use the 'imagesc' function as mentioned by @DGM.
Here's the script with the changes:
clear
clc
close all
% Generate example data
x = 100;
y = 50;
data = zeros(y, x);
% Fill the data array (your existing code)
data(1,1) = 50;
dchartdx = 25/x;
dchartdy = 25/y;
for ii = 1:x
data(1,ii+1) = data(1,ii) + dchartdx;
end
for ii = 1:x+1
for ij = 1:y
data(ij+1,ii) = data(ij,ii) + dchartdy;
end
end
% Create the plot
figure;
imagesc(1:x, 1:y, data); % display the data with the colormap ends corresponding to the data extrema
colormap(flipud(hot)); % specify a colormap
colorbar; % add a colorbar
% Set axis labels and title
xlabel('Range (km)');
ylabel('Depth (m)');
title('Data Visualization');
% Invert the y-axis to have (1,1) at the top-left corner
set(gca, 'YDir', 'reverse');
% Adjust aspect ratio if needed
axis equal tight
I hope this helps!

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by