Different color scale?

96 views (last 30 days)
Ara
Ara on 25 Nov 2024 at 11:04
Commented: Ara on 7 Dec 2024 at 8:35
Dear all,
I have two different dataset one in txt format (ROTI output) and another in xlsx format(S4 output).I wanted to plot different scalebar with different color so that I can recognize these two data set. Would you please tell me the command of it?
Thank you,
Aramesh
  4 Comments
Mathieu NOE
Mathieu NOE on 25 Nov 2024 at 16:02
hello @Ara
it would help us (and you BTW) if you could share a working code and the data
all the best
Ara
Ara on 26 Nov 2024 at 6:45
Hi Mathieu NOE,
Thank you for your comment. Unfortunately, I cannot share the data.
Best wishes,

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 25 Nov 2024 at 17:48
You need to use the colormap function to set the colormap for each axes independently. So display one image, set the colormap, then display the other and call colormap again with the other colormap. If you're plotting line curves instead of displaying images, there is a 'Color' (or maybe 'LineColor' option in plot to let you set the specific color of each curve.
help colormap
colormap - View and set current colormap This MATLAB function sets the colormap for the current figure to the specified predefined colormap. Set Colormap colormap map colormap(map) colormap(target,map) cmap = colormap(___) Get Current Colormap cmap = colormap cmap = colormap(target) Input Arguments map - Colormap for new color scheme colormap name | three-column matrix of RGB triplets | 'default' target - Target Figure object | Axes object | PolarAxes object | GeographicAxes object | standalone visualization Output Arguments cmap - Colormap values three-column matrix of RGB triplets Examples openExample('graphics2/ChangeColormapUsedForPlotExample') openExample('graphics2/ChangeColormapThenSetItBackToDefaultExample') openExample('graphics/ColormapSpecifyAxesTiledLayoutExample') openExample('graphics2/SpecifyNumberOfColorsForColormapExample') openExample('graphics2/CreateCustomColormapExample') openExample('graphics2/ReturnColormapValuesUsedInPlotExample') openExample('graphics/ColormapReturnFromTiledLayoutExample') openExample('graphics2/ChangeColormapForFigureWithImageExample') See also colorbar, ind2rgb, hsv2rgb, rgbplot, Colormap Editor Introduced in MATLAB before R2006a Documentation for colormap doc colormap
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
  3 Comments
Image Analyst
Image Analyst on 26 Nov 2024 at 14:44
I don't know what you want. What color ranges do you want for the left colorbar and right colorbar, and what numerical data values do the top and bottom of the colorbars represent?
Ara
Ara on 27 Nov 2024 at 8:09
Dear Image Analysis,
I want to show different threshold for ROTI (0-0.5) and S4 (0-0.3) in one map. ALso, show different color bar. I set "jet" for one of them and "hot" for another one but it does not appear on the plot.

Sign in to comment.


Walter Roberson
Walter Roberson on 25 Nov 2024 at 18:53
caxis([0 0.3]);
That is affecting the current axis.
caxis([0 0.5]);
That too is affecting the current axis. Which appears to be the same axis as before.
Each axis has only one CLim axis property, so only one caxis() can be in effect at the same time in each axis.
If you need two different caxis() then you need two different axes.
  14 Comments
Ara
Ara on 4 Dec 2024 at 11:43
here is with different axex but again only show 0.5 for both.
% Create a VideoWriter object for the output video
video_filename = 'S4_and_ROTI_SingleMap_Axes.mp4';
v = VideoWriter(video_filename, 'MPEG-4');
v.FrameRate = 2; % Adjust frame rate
open(v);
% Latitude and longitude limits for Europe
latlim = [20 90];
lonlim = [-30 60];
% Define the time range (5-minute intervals for a full day)
start_time = datetime(2023, 4, 24, 0, 0, 0);
end_time = datetime(2023, 4, 24, 23, 59, 59);
time_bins = start_time:minutes(5):end_time;
% Initialize variables for ROTI data
all_lat = [];
all_lon = [];
all_roti = [];
filtered_time_hours_all = [];
% List of ROTI data files
fileNames = {'Dataajac.txt', 'Dataasky.txt', 'Dataflrs.txt', 'Datafunc.txt', ...
'Datahamd.txt', 'Datahrmn.txt', 'Datalamp.txt', ...
'Datalpal.txt', 'Datalyns.txt', 'Datamdvj.txt', 'Datametg.txt', ...
'Datanklg.txt', 'Dataorid.txt', 'Datapolv.txt', 'Datareyk.txt', ...
'Datariga.txt', 'Datarink.txt', 'Datascor.txt', 'Datasenu.txt', ...
'Datasulp.txt', 'Datatro1.txt'};
% Process ROTI data files
for f = 1:length(fileNames)
fileName = fileNames{f};
try
% Read ROTI data
data = readmatrix(fileName);
time_mjd = data(:, 1); % MJD time
ROTI = data(:, 8); % ROTI values
IPP_lon = data(:, 10); % Longitude
IPP_lat = data(:, 11); % Latitude
% Convert MJD to hours since start of the day
mjd_start = floor(min(time_mjd));
time_hours = (time_mjd - mjd_start) * 24;
% Filter for specific time range (20 to 44 hours)
time_filter = time_hours >= 20 & time_hours < 44;
filtered_time_hours = time_hours(time_filter) - 20;
% Append filtered data
all_lat = [all_lat; IPP_lat(time_filter)];
all_lon = [all_lon; IPP_lon(time_filter)];
all_roti = [all_roti; ROTI(time_filter)];
filtered_time_hours_all = [filtered_time_hours_all; filtered_time_hours];
catch
disp(['Skipping file: ', fileName, ' due to an error.']);
end
end
% Initialize variables for S4 data
all_S4_data = struct('time_dt', {}, 'S4', {}, 'Lon_IPP', {}, 'Lat_IPP', {});
% Process S4 data from station files
for station_num = 1:29
filename = sprintf('Station%d.xlsx', station_num);
try
% Read S4 data
data = readmatrix(filename, 'OutputType', 'string');
time_str = data(:, 1); % Time strings
S4 = str2double(data(:, 3)); % S4 values
Lon_IPP = str2double(data(:, 15)); % Longitude
Lat_IPP = str2double(data(:, 16)); % Latitude
elevation = str2double(data(:, 5)); % Elevation angle
% Convert time strings to datetime format
time_dt = datetime(time_str, 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.SSS');
% Apply filters
date_filter = (time_dt >= start_time) & (time_dt <= end_time) & (elevation >= 30);
if any(date_filter)
all_S4_data(station_num).time_dt = time_dt(date_filter);
all_S4_data(station_num).S4 = S4(date_filter);
all_S4_data(station_num).Lon_IPP = Lon_IPP(date_filter);
all_S4_data(station_num).Lat_IPP = Lat_IPP(date_filter);
end
catch
disp(['Error processing Station ', num2str(station_num)]);
end
end
% Create figure for plotting
figure('Position', [100, 100, 1200, 800]); % Larger figure
% Loop through each 5-minute interval and create frames
for i = 1:length(time_bins) - 1
clf; % Clear the figure
% Create world map
ax1 = worldmap(latlim, lonlim);
setm(ax1, 'FFaceColor', [0.5 0.7 0.9]);
load coastlines;
geoshow(coastlat, coastlon, 'DisplayType', 'polygon', 'FaceColor', [0.6 0.8 0.6]);
% Plot S4 data
for station_num = 1:length(all_S4_data)
if ~isempty(all_S4_data(station_num).time_dt)
current_interval = (all_S4_data(station_num).time_dt >= time_bins(i)) & ...
(all_S4_data(station_num).time_dt < time_bins(i + 1));
if any(current_interval)
scatterm(all_S4_data(station_num).Lat_IPP(current_interval), ...
all_S4_data(station_num).Lon_IPP(current_interval), ...
40, all_S4_data(station_num).S4(current_interval), ...
'filled', 'MarkerEdgeColor', 'k', 'MarkerFaceAlpha', 0.6);
end
end
end
% Add colorbar for S4
colormap(ax1, jet);
c1 = colorbar('Location', 'eastoutside');
c1.Label.String = 'S4';
caxis(ax1, [0 0.3]); % Set color axis limits for S4
% Create another map for ROTI
ax2 = worldmap(latlim, lonlim); % Axis for ROTI
setm(ax2, 'FFaceColor', 'none'); % Make the background transparent
load coastlines
geoshow(coastlat, coastlon, 'DisplayType', 'polygon', 'FaceColor', [0.6 0.8 0.6]);
hold on; % Allow overlay of ROTI data
% Plot ROTI data
idx = filtered_time_hours_all >= (i-1)*5/60 & filtered_time_hours_all < i*5/60;
if any(idx)
scatterm(all_lat(idx), all_lon(idx), 10, all_roti(idx), 'filled', 'Marker', 's');
% Add colorbar for ROTI
c2 = colorbar('Location', 'westoutside');
c2.Label.String = 'ROTI (TECU/min)';
caxis(ax2, [0 0.5]); % Set color axis limits for ROTI
end
% Add title
title(['S4 and ROTI Data at ', datestr(time_bins(i), 'HH:MM')]);
% Capture frame for video
frame = getframe(gcf);
writeVideo(v, frame);
end
% Close the video writer
close(v);
disp(['Video saved as ', video_filename]);
Ara
Ara on 7 Dec 2024 at 8:35
Hi Walter,
Sorry for bothering you again. But, I got the same problem after set different axes. It still shows both colorbar for 0.5 only. Do you have any suggestions?
Thank you.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!