Plotting 2 different color maps on one world map
Mostra commenti meno recenti
Is it possible to plot 2 different color maps on the worldmap figure? I have a .tif file and a .nc file that are both color scales and I want to overlay them. Currently the code I have will plot them both, but using the same color scale:
figure
hold on
worldmap([69,79], [-167,-117])
colormap('bone');
geoshow([.tif file] A2,R2,DisplayType="surface")
colorbar
colormap('winter')
geoshow([.nc file],,'DisplayType','surface', 'FaceAlpha', 0.2)
colorbar
Is there any way to have 2 different colormaps? Thank you!
3 Commenti
DGM
il 10 Set 2024
An axes can have one colormap, which is applied to all descendant objects are colormapped.
If you want to have two objects with different colormaps, then you need to overlay two axes.
Hi @Judy Wu,
Based on @DGM comments, here is a sample code snippet that demonstrates how to overlay two different colormaps on a world map:
% Load the .tif and .nc files
A2 = imread('your_file.tif'); % Replace with your .tif file path
R2 = maprefpost('your_file.tif'); % Replace with your .tif reference
data_nc = ncread('your_file.nc', 'variable_name'); % Replace with your .nc file and variable
% Create a world map
figure;
worldmap([69, 79], [-167, -117]);
% Create first axes for the .tif file
ax1 = axes('Position', get(gca, 'Position')); % Get current axes position
hold on;
geoshow(ax1, A2, R2, 'DisplayType', 'surface');
colormap(ax1, 'bone'); % Apply first colormap
colorbar(ax1); % Add colorbar for the first dataset
% Create second axes for the .nc file
ax2 = axes('Position', get(gca, 'Position')); % Use the same position
hold on;
geoshow(ax2, data_nc, 'DisplayType', 'surface', 'FaceAlpha', 0.2); % Adjust transparency
colormap(ax2, 'winter'); % Apply second colormap
colorbar(ax2); % Add colorbar for the second dataset
% Set the visibility of the axes
set(ax1, 'Color', 'none'); % Make the background transparent
set(ax2, 'Color', 'none'); % Make the background transparent
When you implement this code, the imread function will load the .tif file, while ncread will load the .nc file. Again, please make sure that you replace the placeholders with your actual file paths and variable names. The axes function is called twice to create two sets of axes that share the same position on the figure and the geoshow function is used to plot each dataset on its respective axes. The FaceAlpha property is set to 0.2 for the second dataset to allow for transparency, making it easier to visualize both datasets simultaneously. Each axes has its own colormap and colorbar, allowing for distinct color representations.
Please let us know if you have any further questions.
Judy Wu
il 11 Set 2024
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Map Creation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

