<?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>modemanager &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/modemanager/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 14 Sep 2011 20:42:40 +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>Controlling plot data-tips</title>
		<link>https://undocumentedmatlab.com/articles/controlling-plot-data-tips?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=controlling-plot-data-tips</link>
					<comments>https://undocumentedmatlab.com/articles/controlling-plot-data-tips#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 20:42:40 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[modemanager]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2432</guid>

					<description><![CDATA[<p>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips">Controlling plot data-tips</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/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-liminclude-properties" rel="bookmark" title="Plot LimInclude properties">Plot LimInclude properties </a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Plot <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/data-cursor-displaying-data-values-interactively.html">data tips</a> are a great visualization aid for Matlab plots. They enable users to interactively click on a plot location and see a tool-tip that contains the clicked location&#8217;s coordinates. The displayed tooltip text is even customizable using documented properties of the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/datacursormode.html">datacursormode</a></b></i> object.<br />
<center><figure style="width: 431px" class="wp-caption aligncenter"><img decoding="async" alt="plot data tips" src="https://undocumentedmatlab.com/images/datatips.png" title="plot data tips" width="431" /><figcaption class="wp-caption-text">plot data tips</figcaption></figure></center><br />
A client has recently asked me to automatically display an attached data-tip to the last data point of a plotted time series of values. The idea was to immediately see what the latest value of the data series is.<br />
Unfortunately, the official documentation clearly says that:</p>
<blockquote><p>You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor).</p></blockquote>
<p>Well, this has never stopped us before, has it?</p>
<h3 id="Creating">Creating new data tips</h3>
<p>Under the hood, data tips use a data-cursor mode, which shares many similarities in behavior and programming code with the other plot modes (zoom, pan, <a target="_blank" href="/articles/accessing-plot-brushed-data/">data-brushing</a>, etc.). At any one time, only a single such mode can be active in any figure window (this is a known limitation of the design). The code itself it actually quite complex and handles numerous edge-cases. Understanding it by simply reading the code (under %matlabroot%\toolbox\matlab\graphics\) is actually pretty difficult. A much easier way to understand the programming flow is to liberally distribute breakpoints (start in <i>datacursormode.m</i>) and interactively activate the functionality, then debug the code step-by-step.<br />
Luckily, it turns out that the code to create a new data-tip is actually quite simple: first get the data-cursor mode object, then create a new data tip using the mode&#8217;s <i>createDatatip()</i> method, update some data-tip properties and finally update the data-tip&#8217;s position:</p>
<pre lang='matlab'>
% First plot the data
hLine = plot(xdata, ydata);
% First get the figure's data-cursor mode, activate it, and set some of its properties
cursorMode = datacursormode(gcf);
set(cursorMode, 'enable','on', 'UpdateFcn',@setDataTipTxt);
% Note: the optional @setDataTipTxt is used to customize the data-tip's content text
% Note: the following code was adapted from %matlabroot%\toolbox\matlab\graphics\datacursormode.m
% Create a new data tip
hTarget = handle(hLine);
hDatatip = cursorMode.createDatatip(hTarget);
% Create a copy of the context menu for the datatip:
set(hDatatip,'UIContextMenu',get(cursorMode,'UIContextMenu'));
set(hDatatip,'HandleVisibility','off');
set(hDatatip,'Host',hTarget);
set(hDatatip,'ViewStyle','datatip');
% Set the data-tip orientation to top-right rather than auto
set(hDatatip,'OrientationMode','manual');
set(hDatatip,'Orientation','top-right');
% Update the datatip marker appearance
set(hDatatip, 'MarkerSize',5, 'MarkerFaceColor','none', ...
              'MarkerEdgeColor','k', 'Marker','o', 'HitTest','off');
% Move the datatip to the right-most data vertex point
position = [xdata(end),ydata(end),1; xdata(end),ydata(end),-1];
update(hDatatip, position);
</pre>
<p>Note: If you don&#8217;t like messing with the code, consider using Tim Farajian&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/19877-makedatatip">MakeDataTip</a> utility, which basically does all this behind the scenes. It is much easier to use as a stand-alone utility, although it does not give you the flexiblility with all the data-tip properties as in the code above.</p>
<h3 id="Updating">Updating an existing data tip</h3>
<p>To modify the appearance of a data-tip, we first need to get access to the <code>hDatatip</code> object that we created earlier, either programmatically, or interactively (or both). Since we can access pre-stored handles only of programmatically-created (not interactively-created) data-tips, we need to use a different method. There are actually two ways to do this:<br />
The basic way is to search the relevant axes for objects that have <b>Tag</b>=&#8217;DataTipMarker&#8217;. For each data-tip, we will get two such handles: one for the marker (<b>Type</b>=&#8217;line&#8217;) and the other for the text box tooltip (<b>Type</b>=&#8217;text&#8217;). We can use these to update (for example) the marker size, color and style; and the text&#8217;s font, border and colors.<br />
A better way is to access the <code>graphics.datatip</code> object itself. This can be done using two hidden properties of the <i><b>datacursormode</b></i> object:</p>
<pre lang='matlab'>
% Get the list of all data-tips in the current figure
>> cursorMode = datacursormode(gcf)
cursorMode =
	graphics.datacursormanager
>> cursorMode.DataCursors
ans =
	graphics.datatip: 2-by-1
>> cursorMode.CurrentDataCursor
ans =
	graphics.datatip
>> cursorMode.CurrentDataCursor.get
            Annotation: [1x1 hg.Annotation]
           DisplayName: ''
           HitTestArea: 'off'
          BeingDeleted: 'off'
         ButtonDownFcn: []
              Children: [2x1 double]
              Clipping: 'on'
             CreateFcn: []
             DeleteFcn: []
            BusyAction: 'queue'
      HandleVisibility: 'off'
               HitTest: 'off'
         Interruptible: 'on'
                Parent: 492.005493164063
    SelectionHighlight: 'on'
                   Tag: ''
                  Type: 'hggroup'
              UserData: []
              Selected: 'off'
             FontAngle: 'normal'
              FontName: 'Helvetica'
              FontSize: 8
             FontUnits: 'points'
            FontWeight: 'normal'
             EdgeColor: [0.8 0.8 0.8]
       BackgroundColor: [1 1 0.933333333333333]
             TextColor: [0 0 0]
                Marker: 'o'
            MarkerSize: 5
       MarkerEdgeColor: 'k'
       MarkerFaceColor: 'none'
       MarkerEraseMode: 'normal'
             Draggable: 'on'
                String: {'Date: 01/09/11'  'Value: 573.24'}
               Visible: 'on'
             StringFcn: []
             UpdateFcn: []
         UIContextMenu: [1x1 uicontextmenu]
                  Host: [1x1 graph2d.lineseries]
           Interpolate: 'off'
</pre>
<p>We can see that the returned <code>graphics.datatip</code> object includes properties of both the text-box and the marker, making it easy to modify. Moreover, we can use its aforementioned <i>update</i> method to move the datatip to a different plot position (see example in the code above). In addition, we can also use the self-explanatory <i>getCursorInfo(), getaxes(), makeCurrent(), movetofront()</i> methods, and a few others.</p>
<h3 id="Properties">Cursor mode and data-tip properties</h3>
<p>The <code>graphics.datacursormanager</code> and the <code>graphics.datatip</code> objects have several public properties that we can use:</p>
<pre lang='matlab'>
>> cursorMode.get
              Enable: 'off'
    SnapToDataVertex: 'on'
        DisplayStyle: 'datatip'
           UpdateFcn: @setDataTipTxt
              Figure: [1x1 figure]
>> cursorMode.CurrentDataCursor.get
            Annotation: [1x1 hg.Annotation]
           DisplayName: ''
           HitTestArea: 'off'
      ... % See the list above
</pre>
<p>Both these objects have plenty of additional hidden properties. You can inspect them using my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect utility</a>. Here is a brief list for reference (R2011b):<br />
<code>graphics.datacursormanager</code>:</p>
<ul>
<li>CurrentDataCursor</li>
<li>DataCursors</li>
<li>Debug</li>
<li>DefaultExportVarName</li>
<li>DefaultPanelPosition</li>
<li>EnableAxesStacking</li>
<li>EnableZStacking</li>
<li>ExternalListeners</li>
<li>HiddenUpdateFcn</li>
<li>NewDataCursorOnClick</li>
<li>OriginalRenderer</li>
<li>OriginalRendererMode</li>
<li>PanelDatatipHandle</li>
<li>PanelHandle</li>
<li>PanelTextHandle</li>
<li>UIContextMenu</li>
<li>UIState</li>
<li>ZStackMinimum</li>
</ul>
<p><code>graphics.datatip</code>:</p>
<ul>
<li>ALimInclude</li>
<li>ApplicationData</li>
<li>Behavior</li>
<li>CLimInclude</li>
<li>DataCursorHandle</li>
<li>DataManagerHandle</li>
<li>Debug</li>
<li>DoThrowStartDragEvent</li>
<li>EmptyArgUpdateFcn</li>
<li>EnableAxesStacking</li>
<li>EnableZStacking</li>
<li>EraseMode</li>
<li>EventObject</li>
<li>ExternalListenerHandles</li>
<li>HelpTopicKey</li>
<li>HostAxes</li>
<li>HostListenerHandles</li>
<li>IncludeRenderer</li>
<li>Invalid</li>
<li>IsDeserializing</li>
<li>MarkerHandle</li>
<li>MarkerHandleButtonDownFcn</li>
<li>Orientation</li>
<li>OrientationMode</li>
<li>OrientationPropertyListener</li>
<li>OriginalDoubleBufferState</li>
<li>PixelBounds</li>
<li>PointsOffset</li>
<li>Position</li>
<li>SelfListenerHandles</li>
<li>Serializable</li>
<li>TextBoxHandle</li>
<li>TextBoxHandleButtonDownFcn</li>
<li>Version</li>
<li>ViewStyle</li>
<li>XLimInclude</li>
<li>YLimInclude</li>
<li>ZLimInclude</li>
<li>ZStackMinimum</li>
<li>uistate</li>
</ul>
<p>As can be seen, if we really want, we can always use the <b>MarkerHandle</b> or <b>TextBoxHandle</b> directly.</p>
<h3 id="Deleting">Deleting data tips</h3>
<p>To delete a specific data-tip, simply call the cursor mode&#8217;s <i>removeDataCursor()</i> method; to delete all data-tips, call its <i>removeAllDataCursors()</i> method:</p>
<pre lang='matlab'>
% Delete the current data-tip
cursorMode.removeDataCursor(cursorMode.CurrentDataCursor)
% Delete all data-tips
cursorMode.removeAllDataCursors()
</pre>
<p>Have you used plot data-tips in some nifty way? If so, please share your experience in a <a href="/articles/controlling-plot-data-tips/#respond">comment</a> below.<br />
p.s. &#8211; did you notice that Java was not mentioned anywhere above? Mode managers use pure-Matlab functionality.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips">Controlling plot data-tips</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/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-liminclude-properties" rel="bookmark" title="Plot LimInclude properties">Plot LimInclude properties </a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/controlling-plot-data-tips/feed</wfw:commentRss>
			<slash:comments>82</slash:comments>
		
		
			</item>
	</channel>
</rss>
