<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>
	Comments on: Customizing contour plots part 2	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-contour-plots-part2</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Tue, 27 Apr 2021 16:05:00 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-510684</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 27 Apr 2021 16:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-510684</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-510683&quot;&gt;Alvaro&lt;/a&gt;.

It is not clear from your comment what command you&#039;re trying to use. You basically have 4 alternatives:
&lt;ol&gt;
	&lt;li&gt;To use the builtin &lt;b&gt;&lt;i&gt;saveas&lt;/i&gt;&lt;/b&gt; function&lt;/li&gt;
	&lt;li&gt;To use the builtin &lt;b&gt;&lt;i&gt;exportgraphics&lt;/i&gt;&lt;/b&gt; function (Matlab R2020a or newer only)&lt;/li&gt;
	&lt;li&gt;To use the &lt;a href=&quot;https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;export_fig&lt;/a&gt; utility&lt;/li&gt;
	&lt;li&gt;To use the &lt;a href=&quot;https://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;screencapture&lt;/a&gt; utility&lt;/li&gt;
&lt;/ol&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-510683">Alvaro</a>.</p>
<p>It is not clear from your comment what command you&#8217;re trying to use. You basically have 4 alternatives:</p>
<ol>
<li>To use the builtin <b><i>saveas</i></b> function</li>
<li>To use the builtin <b><i>exportgraphics</i></b> function (Matlab R2020a or newer only)</li>
<li>To use the <a href="https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig" target="_blank" rel="nofollow">export_fig</a> utility</li>
<li>To use the <a href="https://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture" target="_blank" rel="nofollow">screencapture</a> utility</li>
</ol>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alvaro		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-510683</link>

		<dc:creator><![CDATA[Alvaro]]></dc:creator>
		<pubDate>Tue, 27 Apr 2021 15:48:38 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-510683</guid>

					<description><![CDATA[Hello all,

First of all let me thank you for your posts they were very helpful.
I implemented a code to show contour labels with scientific notation in latex format &quot;mantissa\cdot 10^{exponent}&quot; based on your guidelines. It was very tedious as matlab resets these labels with many things (even not doing it when debugging the function for the plot but yes when invoking it). 
Currently I reach the figures with contours seen with the abovementioned format. I can save them manually clicking in saveas but... when I try to save the figure automatically from a script using command , the figure in this case updates to the previous contour labels format. 
Unbelievable! Did you find any solution for this?
Thanks!]]></description>
			<content:encoded><![CDATA[<p>Hello all,</p>
<p>First of all let me thank you for your posts they were very helpful.<br />
I implemented a code to show contour labels with scientific notation in latex format &#8220;mantissa\cdot 10^{exponent}&#8221; based on your guidelines. It was very tedious as matlab resets these labels with many things (even not doing it when debugging the function for the plot but yes when invoking it).<br />
Currently I reach the figures with contours seen with the abovementioned format. I can save them manually clicking in saveas but&#8230; when I try to save the figure automatically from a script using command , the figure in this case updates to the previous contour labels format.<br />
Unbelievable! Did you find any solution for this?<br />
Thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-471157</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 29 Mar 2019 13:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-471157</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-470415&quot;&gt;Shan&lt;/a&gt;.

@Shan - The &lt;code&gt;ax.YDir=&#039;reverse&#039;&lt;/code&gt; command, and any other similar command that repaints the axes, reverts the EdgePrims to their default (documented) behavior. So after any such command, you need to redo the setting of the undocumented functionality (&lt;code&gt;set(hContour.EdgePrims...)&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-470415">Shan</a>.</p>
<p>@Shan &#8211; The <code>ax.YDir='reverse'</code> command, and any other similar command that repaints the axes, reverts the EdgePrims to their default (documented) behavior. So after any such command, you need to redo the setting of the undocumented functionality (<code>set(hContour.EdgePrims...)</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Shan		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-470415</link>

		<dc:creator><![CDATA[Shan]]></dc:creator>
		<pubDate>Tue, 26 Mar 2019 13:59:50 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-470415</guid>

					<description><![CDATA[Hi,
Thank you so much for this improvement.
But when I use the function &lt;code&gt;ax=gca&lt;/code&gt;, it will overrun the &lt;code&gt;set(hContour.EdgePrims(hContour.LevelList&#060;0),&#039;LineStyle&#039;,&#039;dotted&#039;);&lt;/code&gt;
here is my code:
&lt;pre lang=&quot;matlab&quot;&gt;
[X,Y,Z] = peaks;
[C,hContour] = contour(peaks,[-8 -6 -4 -2 -0 2 4 6 8], &#039;ShowText&#039;,&#039;on&#039;); drawnow
set(hContour.EdgePrims(hContour.LevelList&lt;0),&#039;LineStyle&#039;,&#039;dotted&#039;);
ax=gca;
ax.YDir = &#039;reverse&#039;;
&lt;/pre&gt;
So do you have any solution for this?
Thanks]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
Thank you so much for this improvement.<br />
But when I use the function <code>ax=gca</code>, it will overrun the <code>set(hContour.EdgePrims(hContour.LevelList&lt;0),'LineStyle','dotted');</code><br />
here is my code:</p>
<pre lang="matlab">
[X,Y,Z] = peaks;
[C,hContour] = contour(peaks,[-8 -6 -4 -2 -0 2 4 6 8], 'ShowText','on'); drawnow
set(hContour.EdgePrims(hContour.LevelList&lt;0),'LineStyle','dotted');
ax=gca;
ax.YDir = 'reverse';
</pre>
<p>So do you have any solution for this?<br />
Thanks</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Steve		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-450503</link>

		<dc:creator><![CDATA[Steve]]></dc:creator>
		<pubDate>Wed, 07 Nov 2018 09:16:19 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-450503</guid>

					<description><![CDATA[You can also use &lt;code&gt;clabel(c,hContour,&#039;FontSize&#039;,10,&#039;Color&#039;,[1 1 1])&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>You can also use <code>clabel(c,hContour,'FontSize',10,'Color',[1 1 1])</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peter Cook		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-417581</link>

		<dc:creator><![CDATA[Peter Cook]]></dc:creator>
		<pubDate>Fri, 15 Dec 2017 22:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-417581</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-417504&quot;&gt;Alon&lt;/a&gt;.

@Alon
This method runs very slow for a complex contour (e.g. not necessarily in size but perhaps one generated from real, noisy, data), which led me to experiment with some other methods. In the case where contour levels are specified to the function, I found a heuristic that seems to work:
&lt;pre lang=&quot;matlab&quot;&gt;
[c,hContour] = contourf(imgaussfilt(noisyData,2),contourLevels);
hL = hContour.EdgePrims;
whichLevels = sum(bsxfun(@eq,c(1,:)&#039;,contourLevels)) &gt; 10;

&gt;&gt; length(contourLevels)
ans =
    32

&gt;&gt; length(hL)
ans =
    24

&gt;&gt; length(contourLevels(whichLevels))
ans =
    24
&lt;/pre&gt;
I&#039;m sure this might fail on some other contour plots, but it has worked on several I generated. Thoughts?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-417504">Alon</a>.</p>
<p>@Alon<br />
This method runs very slow for a complex contour (e.g. not necessarily in size but perhaps one generated from real, noisy, data), which led me to experiment with some other methods. In the case where contour levels are specified to the function, I found a heuristic that seems to work:</p>
<pre lang="matlab">
[c,hContour] = contourf(imgaussfilt(noisyData,2),contourLevels);
hL = hContour.EdgePrims;
whichLevels = sum(bsxfun(@eq,c(1,:)',contourLevels)) > 10;

>> length(contourLevels)
ans =
    32

>> length(hL)
ans =
    24

>> length(contourLevels(whichLevels))
ans =
    24
</pre>
<p>I&#8217;m sure this might fail on some other contour plots, but it has worked on several I generated. Thoughts?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alon		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-417504</link>

		<dc:creator><![CDATA[Alon]]></dc:creator>
		<pubDate>Wed, 13 Dec 2017 14:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-417504</guid>

					<description><![CDATA[Hello Yair,
Note that if there are unused contour lines, as may be the case when &lt;code&gt;hContour.LevelListMode&lt;/code&gt; is set to &lt;code&gt;manual&lt;/code&gt;, the above code will not work, as &lt;code&gt;hContour.EdgePrims&lt;/code&gt; enumerates only the visible contour lines (while not hinting at the contour level they are related to), while &lt;code&gt;hContour.LevelList&lt;/code&gt; enumerates them all.
Instead, you must enumerate the visible contour lines:
&lt;pre lang=&quot;matlab&quot;&gt;
k = 1;
activecontours = [];
while k &lt; size(hContour.ContourMatrix,2)
    activecontours = [activecontours hContour.ContourMatrix(1,k)];
    k = k + hContour.ContourMatrix(2,k) + 1;
end
levels = unique(activecontours);
&lt;/pre&gt;
Then use the &lt;code&gt;levels&lt;/code&gt; generated in the code you supplied.

Best regards,
Alon]]></description>
			<content:encoded><![CDATA[<p>Hello Yair,<br />
Note that if there are unused contour lines, as may be the case when <code>hContour.LevelListMode</code> is set to <code>manual</code>, the above code will not work, as <code>hContour.EdgePrims</code> enumerates only the visible contour lines (while not hinting at the contour level they are related to), while <code>hContour.LevelList</code> enumerates them all.<br />
Instead, you must enumerate the visible contour lines:</p>
<pre lang="matlab">
k = 1;
activecontours = [];
while k < size(hContour.ContourMatrix,2)
    activecontours = [activecontours hContour.ContourMatrix(1,k)];
    k = k + hContour.ContourMatrix(2,k) + 1;
end
levels = unique(activecontours);
</pre>
<p>Then use the <code>levels</code> generated in the code you supplied.</p>
<p>Best regards,<br />
Alon</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416609</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 18 Nov 2017 15:57:20 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-416609</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416561&quot;&gt;Elbio&lt;/a&gt;.

Unlike &lt;i&gt;&lt;b&gt;contour&lt;/b&gt;&lt;/i&gt;, the &lt;i&gt;&lt;b&gt;contourf&lt;/b&gt;&lt;/i&gt; function returns a list of levels that includes the minimum value, which does not correspond to any contour line (&lt;code&gt;[-6.5466,-6,-5,-4,...]&lt;/code&gt; rather than &lt;code&gt;[-6,-5,-4,...]&lt;/code&gt;). So the solution for &lt;i&gt;&lt;b&gt;contourf&lt;/b&gt;&lt;/i&gt; is simply to equate &lt;code&gt;levels(2:end)&lt;/code&gt; with &lt;code&gt;lines&lt;/code&gt;, as follows:

&lt;pre lang=&quot;matlab&quot;&gt;
[c,hContour] = contourf(peaks, &#039;LevelStep&#039;,1, &#039;ShowText&#039;,&#039;on&#039;); drawnow
levels = hContour.LevelList(2:end);
lines  = hContour.EdgePrims;
set(lines(levels&lt;0),  &#039;LineStyle&#039;, &#039;dotted&#039;);
set(lines(levels==0), &#039;LineWidth&#039;, 2);
&lt;/pre&gt;
&lt;img src=&quot;http://undocumentedmatlab.com/images/contour_labels_4.png&quot; width=&quot;400&quot; height=&quot;300&quot; /&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416561">Elbio</a>.</p>
<p>Unlike <i><b>contour</b></i>, the <i><b>contourf</b></i> function returns a list of levels that includes the minimum value, which does not correspond to any contour line (<code>[-6.5466,-6,-5,-4,...]</code> rather than <code>[-6,-5,-4,...]</code>). So the solution for <i><b>contourf</b></i> is simply to equate <code>levels(2:end)</code> with <code>lines</code>, as follows:</p>
<pre lang="matlab">
[c,hContour] = contourf(peaks, 'LevelStep',1, 'ShowText','on'); drawnow
levels = hContour.LevelList(2:end);
lines  = hContour.EdgePrims;
set(lines(levels&lt;0),  'LineStyle', 'dotted');
set(lines(levels==0), 'LineWidth', 2);
</pre>
<p><img src="http://undocumentedmatlab.com/images/contour_labels_4.png" width="400" height="300" /></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Elbio		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416561</link>

		<dc:creator><![CDATA[Elbio]]></dc:creator>
		<pubDate>Fri, 17 Nov 2017 14:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-416561</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416543&quot;&gt;Yair Altman&lt;/a&gt;.

Hi Yair:

Many thanks for your helpful answer. I found a problem though when using contourf.
&lt;pre lang=&quot;matlab&quot;&gt;
[c,h] = contourf(peaks,&#039;LevelStep&#039;,1); drawnow
levels = h.LevelList;
lines  = h.EdgePrims;
set(lines(levels&lt;0),  &#039;LineStyle&#039;, &#039;dotted&#039;);
set(lines(levels==0), &#039;LineWidth&#039;, 2);
&lt;/pre&gt;

Instead of highlighting the zero line it is the &quot;1&quot; line the one that appears wider. 
It might be related to the different size of the &lt;code&gt;levels&lt;/code&gt; and &lt;code&gt;lines&lt;/code&gt; arrays. For example if I tried to change the linestyle using:
&lt;pre lang=&quot;matlab&quot;&gt;
[c,h] = contourf(peaks,[-9:1:9]);
levels = h.LevelList;
lines  = h.EdgePrims;
set(lines(levels&lt;0), &#039;LineStyle&#039;, &#039;dotted&#039;);
&lt;/pre&gt;
there are dotted lines with positive values.

Regards,
Elbio.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416543">Yair Altman</a>.</p>
<p>Hi Yair:</p>
<p>Many thanks for your helpful answer. I found a problem though when using contourf.</p>
<pre lang="matlab">
[c,h] = contourf(peaks,'LevelStep',1); drawnow
levels = h.LevelList;
lines  = h.EdgePrims;
set(lines(levels&lt;0),  'LineStyle', 'dotted');
set(lines(levels==0), 'LineWidth', 2);
</pre>
<p>Instead of highlighting the zero line it is the "1" line the one that appears wider.<br />
It might be related to the different size of the <code>levels</code> and <code>lines</code> arrays. For example if I tried to change the linestyle using:</p>
<pre lang="matlab">
[c,h] = contourf(peaks,[-9:1:9]);
levels = h.LevelList;
lines  = h.EdgePrims;
set(lines(levels&lt;0), 'LineStyle', 'dotted');
</pre>
<p>there are dotted lines with positive values.</p>
<p>Regards,<br />
Elbio.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416543</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 17 Nov 2017 08:17:36 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7149#comment-416543</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416528&quot;&gt;Elbio&lt;/a&gt;.

@Elbio - in HG2 (R2014b or newer) the contour lines (hContour.&lt;b&gt;EdgePrims&lt;/b&gt;) correspond to the contour levels (hContour.&lt;b&gt;LevelList&lt;/b&gt;). For example, to make all negative contour lines dotted, you can do the following:
&lt;pre lang=&quot;matlab&quot;&gt;
[C,hContour] = contour(peaks, &#039;ShowText&#039;,&#039;on&#039;, &#039;LevelStep&#039;,1); drawnow
set(hContour.EdgePrims(hContour.LevelList&lt;0), &#039;LineStyle&#039;, &#039;dotted&#039;);
&lt;/pre&gt;
I added an explanation and screenshot to the main article text above.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2#comment-416528">Elbio</a>.</p>
<p>@Elbio &#8211; in HG2 (R2014b or newer) the contour lines (hContour.<b>EdgePrims</b>) correspond to the contour levels (hContour.<b>LevelList</b>). For example, to make all negative contour lines dotted, you can do the following:</p>
<pre lang="matlab">
[C,hContour] = contour(peaks, 'ShowText','on', 'LevelStep',1); drawnow
set(hContour.EdgePrims(hContour.LevelList&lt;0), 'LineStyle', 'dotted');
</pre>
<p>I added an explanation and screenshot to the main article text above.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
