<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adrian Cherry &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/adrian-cherry/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 07 Feb 2011 18:00:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Multi-column (grid) legend</title>
		<link>https://undocumentedmatlab.com/articles/multi-column-grid-legend?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multi-column-grid-legend</link>
					<comments>https://undocumentedmatlab.com/articles/multi-column-grid-legend#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 07 Feb 2011 18:00:04 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Listeners]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Adrian Cherry]]></category>
		<category><![CDATA[Listener]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[scribe]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2071</guid>

					<description><![CDATA[<p>This article explains how to use undocumented axes listeners for implementing multi-column plot legends</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-column-grid-legend">Multi-column (grid) legend</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparent-legend" rel="bookmark" title="Transparent legend">Transparent legend </a> <small>Matlab chart legends are opaque be default but can be made semi- or fully transparent. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-customization" rel="bookmark" title="Plot legend customization">Plot legend customization </a> <small>Matlab plot legends and their internal components can be customized using a variety of undocumented properties that are easily accessible. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-title" rel="bookmark" title="Plot legend title">Plot legend title </a> <small>Titles to plot legends are easy to achieve in HG1 (R2014a or earlier), but much more difficult in HG2 (R2014b or newer). ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to welcome guest blogger Adrian Cherry. Adrian will describe a very handy utility that shows how basic built-in Matlab functions can be improved and customized by just a bit of fiddling under Matlab&#8217;s hood.</i></p>
<h3 id="Legend">Legend Plotting</h3>
<p>Whilst I enjoy using the many time saving features of Matlab, one area where I feel it suffers is the technical plotting and annotation. This tale relates the development of a legend plotting routine, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29248-gridlegend-a-multi-column-format-for-legends">gridLegend</a>, in an effort to improve the presentation.<br />
In my day job we have a requirement to condense a large quantity of data onto summary charts. However, there is only so much data consolidation possible before you start losing the information required. We often need to plot 40 or 50 lines of test data to visualize trends or outliers, using the legend to identify the number of test hours against each test specimen.<br />
Using the standard Matlab <i><b>legend</b></i> function resulted in a long legend over twice the size of the associated plot:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" alt="Standard Matlab legend" src="https://undocumentedmatlab.com/images/Legend1.png" title="Standard Matlab legend" width="450" height="337" /><figcaption class="wp-caption-text">Standard Matlab legend</figcaption></figure></center><br />
I wanted some way of generating a more compact legend format.<br />
Fortunately earlier in the year, an entry on Matlab Central allowing a multi-column legend to be generated was posted, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/27389-columnlegend">columnlegend</a>. Although lacking some features, columnlegend gave me a good start on developing what I wanted for a multi column legend, culminating in <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29248-gridlegend-a-multi-column-format-for-legends">gridLegend</a>:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img decoding="async" alt="Multi-column legend" src="https://undocumentedmatlab.com/images/Legend2.png" title="Multi-column legend" width="450" height="398" /><figcaption class="wp-caption-text">Multi-column legend</figcaption></figure></center></p>
<h3 id="Undocumented">Delving into the Undocumented Matlab</h3>
<p>So where is the link with undocumented Matlab?<br />
As mentioned in the original columnlegend entry, it was relatively simple to redraw the legend as required on the screen. However, as soon as the figure was printed or exported to an image file, internal Matlab workings would redraw the figure, including the legend, thereby undoing my careful legend crafting, squeezing it back into one column (Yuck!):<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img decoding="async" alt="Matlab-reverted multi-column legend" src="https://undocumentedmatlab.com/images/Legend3.png" title="Matlab-reverted multi-column legend" width="450" height="398" /><figcaption class="wp-caption-text">Matlab-reverted multi-column legend</figcaption></figure></center><br />
As we wanted to automatically output images files, I had to delve into the hidden areas of Matlab to try to solve this problem.<br />
My initial thought was to find out where the figure got redrawn for printing or export and override the standard legend call with a call to my new function. I couldn&#8217;t find the obvious culprit, stepping as far as I could through the print function there didn&#8217;t appear to be any call to the legend function.<br />
In my search for information on how the legend worked I found the undocumented Matlab article about generating <a target="_blank" href="/articles/legend-semi-documented-feature/">dynamic legends</a>. This dynamic-legend post covered details about attaching a listener to a child of the legend axes, in Matlab the legend function creates its own set of axes on the figure to display the legend.<br />
Armed with the information that legend axes objects could have listeners attached, I considered that these might be the source of redrawing the legend for printing. So with the legend I had generated I took a look at what listeners were attached, using the undocumented hidden axes property <b>ScribeLegendListeners</b>:</p>
<pre lang="matlab">
>> legendListener = get(gca,'ScribeLegendListeners')
legendListener =
        fontname: [1x1 handle.listener]
        fontsize: [1x1 handle.listener]
      fontweight: [1x1 handle.listener]
       fontangle: [1x1 handle.listener]
       linewidth: [1x1 handle.listener]
         deleted: [1x1 handle.listener]
    proxydeleted: [1x1 handle.listener]
</pre>
<p>The font size and line positioning were all being redrawn for printing so this was potentially the source of my problem. However I&#8217;d not looked at a <i><b>handle.listener</b></i> before, so a little further digging was required:</p>
<pre lang="matlab">
K>> get(legendListener.fontname)
      SourceObject: [1x1 schema.prop]
         Container: [1x1 axes]
         EventType: 'PropertyPostSet'
          Callback: {2x1 cell}
    CallbackTarget: []
           Enabled: 'on'
</pre>
<p>The option <b>Enabled</b> immediately drew my attention, and so the following lines were added to my gridLegend function to switch off these listeners and apply it back to the legend:</p>
<pre lang="matlab">
LL = get(gca,'ScribeLegendListeners');
set(LL.fontname,'enabled','off');
set(LL.fontsize,'enabled','off');
set(LL.fontweight,'enabled','off');
set(LL.fontangle,'enabled','off');
set(LL.linewidth,'enabled','off');
set(gca,'ScribeLegendListeners',LL);
</pre>
<p>Finally allowing me to output the image files with a multi-column legend:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Printed multi-column legend" src="https://undocumentedmatlab.com/images/Legend4.jpg" title="Printed multi-column legend" width="450" height="363" /><figcaption class="wp-caption-text">Printed multi-column legend</figcaption></figure></center><br />
So my thanks to the contributors on Matlab Central who enabled me to get started on gridLegend and to Yair for collating the many nuggets of information on Undocumented Matlab which allowed me to complete the function and get it posted on Matlab Central.<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Multi-column legend in action" src="https://undocumentedmatlab.com/images/gridLegend.jpg" title="Multi-column legend in action" width="450" height="300" /><figcaption class="wp-caption-text">Multi-column legend in action</figcaption></figure></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-column-grid-legend">Multi-column (grid) legend</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparent-legend" rel="bookmark" title="Transparent legend">Transparent legend </a> <small>Matlab chart legends are opaque be default but can be made semi- or fully transparent. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-customization" rel="bookmark" title="Plot legend customization">Plot legend customization </a> <small>Matlab plot legends and their internal components can be customized using a variety of undocumented properties that are easily accessible. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-title" rel="bookmark" title="Plot legend title">Plot legend title </a> <small>Titles to plot legends are easy to achieve in HG1 (R2014a or earlier), but much more difficult in HG2 (R2014b or newer). ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/multi-column-grid-legend/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
