- 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?
107 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Adam Danz
2022-9-19
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 个评论
更多回答(1 个)
vamshi sai yele
2022-9-19
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!