<?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: Plot line transparency and color gradient	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plot-line-transparency-and-color-gradient</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 26 May 2022 19:36:11 +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/plot-line-transparency-and-color-gradient#comment-514162</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 26 May 2022 19:36:11 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-514162</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-514133&quot;&gt;Cesim Dumlu&lt;/a&gt;.

When you use plot() without hold(&#039;on&#039;), each new plot() clears the axes and draws a new line, so your second plot() of p2 caused the first plot() line (p1) to be erased. 
Add a call to hold(&#039;on&#039;) before you plot to ensure that both lines are ploted and not deleted.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-514133">Cesim Dumlu</a>.</p>
<p>When you use plot() without hold(&#8216;on&#8217;), each new plot() clears the axes and draws a new line, so your second plot() of p2 caused the first plot() line (p1) to be erased.<br />
Add a call to hold(&#8216;on&#8217;) before you plot to ensure that both lines are ploted and not deleted.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Cesim Dumlu		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-514133</link>

		<dc:creator><![CDATA[Cesim Dumlu]]></dc:creator>
		<pubDate>Fri, 20 May 2022 12:06:14 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-514133</guid>

					<description><![CDATA[Hello. I am trying to do a gradient plot for multiple functions to be displayed on the same axes and each one is colorcoded by respective colordata,  using the same  scaling. The sample code is below:
&lt;pre lang=&quot;matlab&quot;&gt;
x = linspace(0,4*pi,150);
y1 = sin(x);
y2 = 1/10*sin(x);
p1 = plot(x,y1);
p2 = plot(x,y2);

cd1 = colormap(&#039;parula&#039;);  %color code for y1
cd1 = interp1(linspace(min(y1),max(y1),length(cd1)),cd1,y1); 
cd1 = uint8(cd1&#039;*255); % need a 4xN uint8 array
cd1(4,:) = 255; % last column is transparency

cd2 = colormap(&#039;parula&#039;);  %colorcode y2
cd2 = interp1(linspace(min(y1),max(y1),length(cd2)),cd2,y2); %uses the same scaling as cd1  
cd2 = uint8(cd2&#039;*255); % need a 4xN uint8 array
cd2(4,:) = 255; % last column is transparency

P={p1.Edge;p2.Edge}; %not sure how this works
NameArray={&#039;ColorBinding&#039;,&#039;ColorData&#039;};
ValueArray={&#039;interpolated&#039;,&#039;cd1&#039;;&#039;interpolated&#039;,&#039;cd2&#039;};
drawnow
set(P,NameArray,ValueArray)
&lt;/pre&gt;
I am getting the error messages. 
&lt;pre lang=&quot;matlab&quot;&gt;
Invalid or deleted object.
Error in trialv4 (line 20)
P={p1.Edge;p2.Edge};
&lt;/pre&gt;
Sorry for the lengthy post. Thanks!]]></description>
			<content:encoded><![CDATA[<p>Hello. I am trying to do a gradient plot for multiple functions to be displayed on the same axes and each one is colorcoded by respective colordata,  using the same  scaling. The sample code is below:</p>
<pre lang="matlab">
x = linspace(0,4*pi,150);
y1 = sin(x);
y2 = 1/10*sin(x);
p1 = plot(x,y1);
p2 = plot(x,y2);

cd1 = colormap('parula');  %color code for y1
cd1 = interp1(linspace(min(y1),max(y1),length(cd1)),cd1,y1); 
cd1 = uint8(cd1'*255); % need a 4xN uint8 array
cd1(4,:) = 255; % last column is transparency

cd2 = colormap('parula');  %colorcode y2
cd2 = interp1(linspace(min(y1),max(y1),length(cd2)),cd2,y2); %uses the same scaling as cd1  
cd2 = uint8(cd2'*255); % need a 4xN uint8 array
cd2(4,:) = 255; % last column is transparency

P={p1.Edge;p2.Edge}; %not sure how this works
NameArray={'ColorBinding','ColorData'};
ValueArray={'interpolated','cd1';'interpolated','cd2'};
drawnow
set(P,NameArray,ValueArray)
</pre>
<p>I am getting the error messages. </p>
<pre lang="matlab">
Invalid or deleted object.
Error in trialv4 (line 20)
P={p1.Edge;p2.Edge};
</pre>
<p>Sorry for the lengthy post. Thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ben Abbott		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-513837</link>

		<dc:creator><![CDATA[Ben Abbott]]></dc:creator>
		<pubDate>Thu, 31 Mar 2022 01:00:40 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-513837</guid>

					<description><![CDATA[Thanks Yair, it was the second. I didn&#039;t not include the drawnow ()]]></description>
			<content:encoded><![CDATA[<p>Thanks Yair, it was the second. I didn&#8217;t not include the drawnow ()</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-513836</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Mar 2022 21:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-513836</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-513835&quot;&gt;Ben Abbott&lt;/a&gt;.

@Ben - it looks perfectly ok (with color gradient and all) on my R2022a... Perhaps you missed some of the steps (e.g. setting the &lt;b&gt;ColorBinding&lt;/b&gt; to &lt;code&gt;&#039;interpolated&#039;&lt;/code&gt;) or perhaps you do not have a &lt;code&gt;drawnow/pause&lt;/code&gt; before you modify the displayed line (i.e. you try to modify the line before Matlab has completed its on-screen rendering).]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-513835">Ben Abbott</a>.</p>
<p>@Ben &#8211; it looks perfectly ok (with color gradient and all) on my R2022a&#8230; Perhaps you missed some of the steps (e.g. setting the <b>ColorBinding</b> to <code>'interpolated'</code>) or perhaps you do not have a <code>drawnow/pause</code> before you modify the displayed line (i.e. you try to modify the line before Matlab has completed its on-screen rendering).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ben Abbott		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-513835</link>

		<dc:creator><![CDATA[Ben Abbott]]></dc:creator>
		<pubDate>Wed, 30 Mar 2022 21:34:49 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-513835</guid>

					<description><![CDATA[The graded color is not working for me using R2021a. The plot &quot;HG2 plot line color, transparency gradient&quot; looks exactly like &quot;Transparent HG2 plot lines&quot;.

Any chance there is a fix?]]></description>
			<content:encoded><![CDATA[<p>The graded color is not working for me using R2021a. The plot &#8220;HG2 plot line color, transparency gradient&#8221; looks exactly like &#8220;Transparent HG2 plot lines&#8221;.</p>
<p>Any chance there is a fix?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: matt		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-510604</link>

		<dc:creator><![CDATA[matt]]></dc:creator>
		<pubDate>Tue, 13 Apr 2021 00:21:42 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-510604</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-452442&quot;&gt;Yaroslav&lt;/a&gt;.

There is no Edge in quiver, so this workaround will not help.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-452442">Yaroslav</a>.</p>
<p>There is no Edge in quiver, so this workaround will not help.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: matt		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-510603</link>

		<dc:creator><![CDATA[matt]]></dc:creator>
		<pubDate>Tue, 13 Apr 2021 00:20:25 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-510603</guid>

					<description><![CDATA[I very much wanted this to work with Quiver, and it does as long as the number of points is not too big. Using 2018a, I get the warnings/errors above even if placed in a single call to set.]]></description>
			<content:encoded><![CDATA[<p>I very much wanted this to work with Quiver, and it does as long as the number of points is not too big. Using 2018a, I get the warnings/errors above even if placed in a single call to set.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: albert		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-457256</link>

		<dc:creator><![CDATA[albert]]></dc:creator>
		<pubDate>Thu, 10 Jan 2019 19:22:12 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-457256</guid>

					<description><![CDATA[Hi,

Take a look at this function, it fades a plot and add new data on it. 
https://www.mathworks.com/matlabcentral/fileexchange/69816-fadeit]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Take a look at this function, it fades a plot and add new data on it.<br />
<a href="https://www.mathworks.com/matlabcentral/fileexchange/69816-fadeit" rel="nofollow ugc">https://www.mathworks.com/matlabcentral/fileexchange/69816-fadeit</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-452442</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Tue, 20 Nov 2018 12:29:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-452442</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-351387&quot;&gt;Sebastian&lt;/a&gt;.

Hi Yair,

There is an issue when there are too many points in the plot as Sebastian &lt;a href=&quot;http://undocumentedmatlab.com/blog/plot-line-transparency-and-color-gradient#comment-351387&quot; rel=&quot;nofollow&quot;&gt;pointed out above&lt;/a&gt;. Below 25000 points, everything works as expected:&lt;pre lang=&quot;matlab&quot;&gt;
% define
N   = 25000;
t   = linspace(0,4*pi,N);
x   = 27*cos(t) + 29*cos(27/2*t);
y   = 27*sin(t) - 29*sin(27/2*t);

% plot
hFig  = figure(&#039;Units&#039;,&#039;normalized&#039;,&#039;Position&#039;,[0.2 0.2 0.4 0.5]);
hAxes = axes(&#039;XTick&#039;,{},&#039;YTick&#039;,{},&#039;NextPlot&#039;,&#039;replacechildren&#039;,&#039;Box&#039;,&#039;on&#039;);
hPlot = plot(x,y);
axis equal tight;
drawnow(); % as required
%
hPlot.Edge.ColorBinding = &#039;interpolated&#039;;
hPlot.Edge.ColorData    = [uint8(parula(N)*255) 255*ones(N,1,&#039;uint8&#039;)]&#039;;
&lt;/pre&gt;
Above this magic number, Matlab tries to optimize the figure by plotting only a subset of the vertices. Repeating the procedure with more points than that results in a warning and no color gradient: &lt;pre lang=&quot;matlab&quot;&gt;
N   = 25001;
...
hPlot.Edge.ColorData    = [uint8(parula(N)*255) 255*ones(N,1,&#039;uint8&#039;)]&#039;;
&lt;/pre&gt; &lt;pre lang=&quot;matlab&quot;&gt;
Warning: Error creating or updating LineStrip
 Error in value of property  ColorData
 Array is wrong shape or size 
&lt;/pre&gt;
To fix the issue, we need to probe the number of vertices in &lt;code&gt;hPlot.Edge&lt;/code&gt;: &lt;pre lang=&quot;matlab&quot;&gt;
N   = 25001;
...
N2  = size(hPlot.Edge.VertexData,2);
hPlot.Edge.ColorData = [uint8(parula(N2)*255) 255*ones(N2,1,&#039;uint8&#039;)]&#039;;
&lt;/pre&gt;
But, if we try, say, to resize the figure, the warning reappears (though the gradient stays): &lt;pre lang=&quot;matlab&quot;&gt;
drawnow(); % just in case...
hFig.Position = [0.2 0.2 0.5 0.6];
&lt;/pre&gt; &lt;pre lang=&quot;matlab&quot;&gt;
Warning: Error creating or updating LineStrip
 Error in value of property  ColorData
 Array is wrong shape or size 
&lt;/pre&gt;
Similar unexpected behavior occurs in &lt;code&gt;zoom&lt;/code&gt;, &lt;code&gt;copyobj&lt;/code&gt; etc.

P.S, my Matlab version is R2018a, so it looks like a rather persistent problem.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-351387">Sebastian</a>.</p>
<p>Hi Yair,</p>
<p>There is an issue when there are too many points in the plot as Sebastian <a href="http://undocumentedmatlab.com/blog/plot-line-transparency-and-color-gradient#comment-351387" rel="nofollow">pointed out above</a>. Below 25000 points, everything works as expected:</p>
<pre lang="matlab">
% define
N   = 25000;
t   = linspace(0,4*pi,N);
x   = 27*cos(t) + 29*cos(27/2*t);
y   = 27*sin(t) - 29*sin(27/2*t);

% plot
hFig  = figure('Units','normalized','Position',[0.2 0.2 0.4 0.5]);
hAxes = axes('XTick',{},'YTick',{},'NextPlot','replacechildren','Box','on');
hPlot = plot(x,y);
axis equal tight;
drawnow(); % as required
%
hPlot.Edge.ColorBinding = 'interpolated';
hPlot.Edge.ColorData    = [uint8(parula(N)*255) 255*ones(N,1,'uint8')]';
</pre>
<p>Above this magic number, Matlab tries to optimize the figure by plotting only a subset of the vertices. Repeating the procedure with more points than that results in a warning and no color gradient: </p>
<pre lang="matlab">
N   = 25001;
...
hPlot.Edge.ColorData    = [uint8(parula(N)*255) 255*ones(N,1,'uint8')]';
</pre>
<pre lang="matlab">
Warning: Error creating or updating LineStrip
 Error in value of property  ColorData
 Array is wrong shape or size 
</pre>
<p>To fix the issue, we need to probe the number of vertices in <code>hPlot.Edge</code>: </p>
<pre lang="matlab">
N   = 25001;
...
N2  = size(hPlot.Edge.VertexData,2);
hPlot.Edge.ColorData = [uint8(parula(N2)*255) 255*ones(N2,1,'uint8')]';
</pre>
<p>But, if we try, say, to resize the figure, the warning reappears (though the gradient stays): </p>
<pre lang="matlab">
drawnow(); % just in case...
hFig.Position = [0.2 0.2 0.5 0.6];
</pre>
<pre lang="matlab">
Warning: Error creating or updating LineStrip
 Error in value of property  ColorData
 Array is wrong shape or size 
</pre>
<p>Similar unexpected behavior occurs in <code>zoom</code>, <code>copyobj</code> etc.</p>
<p>P.S, my Matlab version is R2018a, so it looks like a rather persistent problem.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ondrej		</title>
		<link>https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient#comment-431667</link>

		<dc:creator><![CDATA[Ondrej]]></dc:creator>
		<pubDate>Wed, 04 Jul 2018 10:09:04 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5200#comment-431667</guid>

					<description><![CDATA[Hi Yair,

I am trying to plot a line with a gradient which would be &quot;perpendicular&quot; to the line. For example:

N = 10;
p = plot(1:N, ones(1, N), &#039;Linewidth&#039;, 20);
cd = [uint8(jet(N)*255) uint8(ones(N, 1))].&#039;;
drawnow
set(p.Edge, &#039;ColorBinding&#039;,&#039;interpolated&#039;, &#039;ColorData&#039;,cd)

This is a horizontal line with color gradient going from left to right (in the direction of the sample points). Is there a way to have a gradient going from top to bottom? (if the line is tilted, then the gradient would be still perpendicular to that line). The effect should look like the line is fading out in the perpendicular direction.

Thanks for any hints and ideas.]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>I am trying to plot a line with a gradient which would be &#8220;perpendicular&#8221; to the line. For example:</p>
<p>N = 10;<br />
p = plot(1:N, ones(1, N), &#8216;Linewidth&#8217;, 20);<br />
cd = [uint8(jet(N)*255) uint8(ones(N, 1))].&#8217;;<br />
drawnow<br />
set(p.Edge, &#8216;ColorBinding&#8217;,&#8217;interpolated&#8217;, &#8216;ColorData&#8217;,cd)</p>
<p>This is a horizontal line with color gradient going from left to right (in the direction of the sample points). Is there a way to have a gradient going from top to bottom? (if the line is tilted, then the gradient would be still perpendicular to that line). The effect should look like the line is fading out in the perpendicular direction.</p>
<p>Thanks for any hints and ideas.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
