Page MenuHomec4science

User_guide2_3.html
No OneTemporary

File Metadata

Created
Sun, Dec 22, 14:22

User_guide2_3.html

<html xmlns:saxon="http://icl.com/saxon">
<head>
<link rel="stylesheet" type="text/css" href="doc.css"/>
<link rel="stylesheet" type="text/css" href=""/>
<meta author="The MathWorks Ltd."/>
<meta copyright="2017 The MathWorks Ltd."/>
<title>Colorbars and legends</title>
</head>
<body>
<table class="header" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#e4f0f8"><A href="User_guide.html"><font face="Arial" bgcolor="#e4f0f8" size="+0" underline="0" color="#000000"><b>User_guide</b></font></A></td>
<td width="36" bgcolor="#e4f0f8"><A HREF="User_guide2_2.html"><IMG SRC="Images/leftarrow.png" BORDER="0" ALT="previous page"/></A><A HREF="User_guide3.html"><IMG SRC="Images/rightarrow.png" BORDER="0" ALT="next page"/></A></td>
</tr>
</table>
<br clear="all"/>
<h2>2.3: Colorbars and legends&nbsp;<a href="User_guide2.html"><img src="Images/uparrow.png" border="0" align="top" alt="Go back up one level"/></a></h2>
<p>(The code for this example can be found here:
[ <a href="Examples/colorbarexample.m">view</a>
| <a href="matlab: edit(fullfile(layoutDocRoot,'Examples','colorbarexample.m'))">edit</a>
| <a href="matlab: p=pwd();cd(fullfile(layoutDocRoot,'Examples')); colorbarexample; cd(p)">run</a> ]
)</p>
<p>
When using layouts to position axes that can also have a
colorbar or legend it is very important to group the axes
with its colorbar and legend by putting them inside a <code>uicontainer</code>.
</p>
<p>
The following example illustrates this.
</p>
<h4>Open a window</h4>
<p>Open a new figure window and remove the toolbar and menus.</p>
<example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011">window = <a href="matlab:doc figure"><code class="FUNCTION">figure</code></a>( 'Name', 'Axes legend and colorbars', ...
'MenuBar', 'none', ...
'Toolbar', 'none', ...
'NumberTitle', 'off' );</font></pre>
</example>
<h4>Create the layout</h4>
<p>The layout involves two axes side by side. Each axes is placed into a uicontainer so that the legend and colorbar are "grouped" with the axes.</p>
<example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011">hbox = <a href="uix.HBoxFlex.html"><code class="FUNCTION">uix.HBoxFlex</code></a>('Parent', window, 'Spacing', 3);
axes1 = <a href="matlab:doc axes"><code class="FUNCTION">axes</code></a>( 'Parent', <a href="matlab:doc uicontainer"><code class="FUNCTION">uicontainer</code></a>('Parent', hbox) );
axes2 = <a href="matlab:doc axes"><code class="FUNCTION">axes</code></a>( 'Parent', <a href="matlab:doc uicontainer"><code class="FUNCTION">uicontainer</code></a>('Parent', hbox) );</font></pre>
<p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/colorbar_example_2.png"/></center></font></p>
</example>
<h4>Add decorations</h4>
<p>Give the first axes a colorbar and the second axes a legend.</p>
<example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"><a href="matlab:doc surf"><code class="FUNCTION">surf</code></a>( axes1, <a href="matlab:doc membrane"><code class="FUNCTION">membrane</code></a>( 1, 15 ) );
<a href="matlab:doc colorbar"><code class="FUNCTION">colorbar</code></a>( axes1 );
<br/>
theta = 0:360;
<a href="matlab:doc plot"><code class="FUNCTION">plot</code></a>( axes2, theta, <a href="matlab:doc sind"><code class="FUNCTION">sind</code></a>(theta), theta, <a href="matlab:doc cosd"><code class="FUNCTION">cosd</code></a>(theta) );
<a href="matlab:doc legend"><code class="FUNCTION">legend</code></a>( axes2, 'sin', 'cos', 'Location', 'NorthWestOutside' );</font></pre>
<p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/colorbar_example_3.png"/></center></font></p>
</example>
<br clear="ALL"/>
<table class="footer" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18" height="15" bgcolor="#e4f0f8" align="left"><a href="User_guide2_2.html"><img src="images/leftarrow.png" border="0" alt="previous page"/></a></td>
<td width="40%" height="15" bgcolor="#e4f0f8" align="left"><a href="User_guide2_2.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Axes inside layouts</font></a></td>
<td width="20%" height="15" bgcolor="#e4f0f8" align="center"><a href="index.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">[Top]</font></a></td>
<td width="40%" height="15" bgcolor="#e4f0f8" align="right"><a href="User_guide3.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Controlling visibility</font></a></td>
<td width="18" height="15" bgcolor="#e4f0f8" align="right"><a href="User_guide3.html"><img src="images/rightarrow.png" border="0" alt="next page"/></a></td>
</tr>
</table>
<font face="Arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">&copy; 2017 The MathWorks Ltd</font>
<TT>&#149; </TT><a href="matlab: termsOfUse">Terms of Use</a>
<TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/patents.txt'])">Patents</a>
<TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/trademarks.txt'])">Trademarks</a>
</body>
</html>

Event Timeline