How to add a colormap to a subplot when using handles?
11 views (last 30 days)
Show older comments
Hi everyone,
I'm currently trying to make a figure that is made up of several surface subplots (of 200x200 data) with a colormap applied to each one. I make each subplot in a loop and apply the settings of them in the loop, when I try to add a colormap (jet, for example) it doesn't apply the colormap to the subplots.
I think this is because I have decided to use handles for the subplots rather than how I was previously starting to writing it (see code below) because there are a lot of subplots and it seemed like a tedious way of doing it. I'm not that familiar with using handles but I have a feeling it is related to that but I can't find a 'colormap' setting in the handle settings in my array so any help/tips would be great
The current method I'm using (I've posted all the code for clarity):
clc; clear all; close all
%Read in averaged experimental images and their fits
N_state = [3 5 6 7 8 9 10 11]; %List of states probed in experiment
num_states = length(N_state); %Number of states probed
filenames = cell(4, 8); %Create a cell array to store the filenames
%String components of the experimental and fitted files
s1 = 'N'; s2 = '_amoeba_';
s_exph = 'mask_h'; s_fith = 'imout_h';
s_expv = 'mask_v'; s_fitv = 'imout_v';
filetype = '.txt';
%For loop for creating the filenames of each file, ordered so each matrix
%element is where the images will be in the diagram
for n = 1:num_states
filenames(1, n) = cellstr(strcat('N', num2str(N_state(1, n)), s2, s_exph, filetype));
filenames(2, n) = cellstr(strcat('N', num2str(N_state(1, n)), s2, s_fith, filetype));
filenames(3, n) = cellstr(strcat('N', num2str(N_state(1, n)), s2, s_expv, filetype));
filenames(4, n) = cellstr(strcat('N', num2str(N_state(1, n)), s2, s_fitv, filetype));
end
images = cell(4,num_states); %Cell array to store the images
%For loop for reading in the images for the figures
for n = 1:num_states
for m = 1:4
images{m,n} = dlmread(char(filenames(m,n)));
end
end
%Dimensions of the figure and properties that might want altering
r = 4; c = 8;
tot = r*c;
pos = 0;
view_az = 0; view_el = 20;
%For loops to plot each subplot with the following settings
figure(1)
for k1 = 1:r
for k2 = 1:c
pos = pos + 1;
subplot(r,c,pos)
s{pos} = surf(images{k1, k2});
view(view_az, view_el)
axis square
zlim([0 inf])
colormap jet %Doesn't change the colormap of the subplots
end
end
The old way is shown here but it did let me apply a colormap:
subplot(r,c,1)
s11 = surf(exp_H); %s11 refers to the 1st row, first column i.e. s[r,c]
colormap jet
shading interp
axis square
view(view_az, view_el)
zlim([0 inf])
set(gca, 'visible', 'off')
subplot(r,c,9)
s12 = surf(fit_H);
colormap jet
shading interp
axis square
view(view_az, view_el)
zlim([0 inf])
%set(gca, 'visible', 'off')
Thanks in advance!
1 Comment
Mohammad Sami
on 25 Jan 2020
colormap can be called as a function.
pass in the axes handle as the first argument.
Accepted Answer
Joseph Leng
on 25 Jan 2020
2 Comments
Mohammad Sami
on 25 Jan 2020
a1 = subplot(211);
surf(a1,peaks);
colormap(a1,'jet');
a2 = subplot(212);
surf(a2,peaks);
colormap(a2,'parula');
More Answers (0)
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!