フィルターのクリア

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

6 ビュー (過去 30 日間)
Matthew
Matthew 2024 年 6 月 16 日
回答済み: Manikanta Aditya 2024 年 7 月 3 日
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 件のコメント
DGM
DGM 2024 年 6 月 16 日
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

サインインしてコメントする。

回答 (1 件)

Manikanta Aditya
Manikanta Aditya 2024 年 7 月 3 日
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!

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by