99 views (last 30 days)
Show older comments
UTKARSH VERMA on 19 Sep 2022
Commented: UTKARSH VERMA on 20 Sep 2022
Accepted Answer: Adam Danz
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 Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Adam Danz on 19 Sep 2022
Open in MATLAB Online
- 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
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
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2)
% 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 Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
UTKARSH VERMA on 19 Sep 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1807995-how-do-i-display-different-colormap-for-subplots#comment_2370740
Hi Adam,
Thanks for your reply.
Can you tell me If I want to use caxis for the each tiledplot, is it possible?
Adam Danz on 19 Sep 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1807995-how-do-i-display-different-colormap-for-subplots#comment_2370850
Indeed!
Call the clim function for each axis specifying the same limits since you're using 1 colorbar scale for those axes.
UTKARSH VERMA on 20 Sep 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1807995-how-do-i-display-different-colormap-for-subplots#comment_2372720
Thanks Adam!
Sign in to comment.
More Answers (1)
vamshi sai yele on 19 Sep 2022
Open in MATLAB Online
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.
Resource-1
Resource-2
Resource-3
Hope you find it helpful!
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
UTKARSH VERMA on 20 Sep 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1807995-how-do-i-display-different-colormap-for-subplots#comment_2372740
Thanks Vamsi, it was great help.
Sign in to comment.
Sign in to answer this question.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office