How to set opacity for the plot?

I have data that should be built in one drawing. Noise data destroys other data. How to change the level of data transparency? In my case, I use the hold all command to build multiple data. One solution is to change LineWidth , but I could not find a way for transparency. I tried alpha as follows

plot( noise_x, 'k', 'LineWidth', 1, 'alpha', 0.2)

but no luck.

+6
source share
2 answers

With the introduction of the new HG2 graphics engine in the Matlab R2014b, things have become pretty easy. Just need a little digging.

Now the color property contains the fourth value for transparency / transparency / face alpha, so all you need to change is:

 x = linspace(-10,10,100); y = x.^2; p1 = plot(x,y,'LineWidth',5); hold on p2 = plot(x,-y+y(1),'LineWidth',5); % // forth value sets opacity p1.Color(4) = 0.5; p2.Color(4) = 0.5; 

enter image description here

Even color gradients are nothing special anymore .

+10
source

You can use the patchline view from File Exchange, in which you can manipulate line objects as if they were patch objects; those. assign them transparency values ​​(alpha).

Here is a sample code using a function:

 clc;clear;close all n = 10; x = 1:n; y1 = rand(1,n); y2 = rand(1,n); y3 = rand(1,n); Y = [y1;y2;y3]; linestyles = {'-';'-';'--'}; colors = {'r';'k';'b'}; alphavalues = [.2 .5 .8]; hold on for k = 1:3 patchline(x,Y(k,:),'linestyle',linestyles{k},'edgecolor',colors{k},'linewidth',4,'edgealpha',alphavalues(k)) end 

and conclusion:

enter image description here

+2
source

All Articles