- Use tiledlayout instead of subplot
- Assign the colormap to the axes using the axes handles
- Using tiledlayout, position the colorbars to the east|west|north|south
How do I display different colormap for subplots?
100 views (last 30 days)
Show older comments
UTKARSH VERMA
on 19 Sep 2022
Commented: UTKARSH VERMA
on 20 Sep 2022
HI all,
I am plotting 6 subplots in one figure in arrangement as 2 rows and 3 colums.
I want two colorbar with different colormap for every row.
How can I do it?
Thanks in advance.
0 Comments
Accepted Answer
Adam Danz
on 19 Sep 2022
Full demo of these 3 steps
tcl = tiledlayout(2,3); % STEP 1
ax = gobjects(1,6);
for i = 1:6
ax(i) = nexttile();
peaks(15);
if i>3
colormap(ax(i),'hot') % STEP 2
else
colormap(ax(i),'cool')
end
end
% STEP 3
cb1 = colorbar(ax(3));
cb1.Layout.Tile = 'east';
cb1.Label.String = 'Vanilla Ice';
cb1 = colorbar(ax(6));
cb1.Layout.Tile = 'east';
cb1.Label.String = 'MC Hammer';
3 Comments
More Answers (1)
vamshi sai yele
on 19 Sep 2022
Hello,
I understood that you want to display different colors in a subplot.
I have tried it from my end and below is the solution for the same.
x=0:0.1:10;
y1 = cos(x)
y2 = sin(x)
subplot(2,2,1)
plot(x,y1,'Color','r') ;
colorbar
subplot(2,2,2)
plot(x,y2,'Color','r') ;
colorbar
subplot(2,2,3)
plot(x,y1,'Color','b') ;
colorbar
subplot(2,2,4)
plot(x,y2,'Color','b') ;
colorbar
In this example we have used 2x2 subplot and assigned red color to first row and blue color to second row. In this way we can set colors to individual plots as well.
We may also include different styled markers with different colors on the graph line. For such more options and better understanding of this concept, kindly refer to the following resources.
Hope you find it helpful!
See Also
Categories
Find more on Blue 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!