- 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?
조회 수: 108 (최근 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!