I have some data to be plotted in one figure. Noise data is ruining other data. How can I change the transparency level of a given data? In my case, I'm using hold all
command for plotting several data. One of the solution is to change the LineWidth
but I couldn't find a way for transparency option. I've tried alpha
as follows
plot( noise_x, 'k', 'LineWidth', 1, 'alpha', 0.2)
but with no luck.
Matplotlib allows you to regulate the transparency of a graph plot using the alpha attribute. By default, alpha=1. If you would like to form the graph plot more transparent, then you'll make alpha but 1, such as 0.5 or 0.25.
There is a property called alpha. After the surf command just say alpha(0.5). The value lies between 0 and 1. The closer to zero the more transparent it is.
Description. alpha value sets the face transparency for objects in the current axes that support transparency. Specify value as 'clear' or 'opaque' , or as a number in the range [0, 1]. A value of 0 makes the objects transparent, and value of 1 makes the objects fully opaque.
In order to change the transparency of a graph plot in matplotlib we will use the matplotlib. pyplot. plot() function.
With the introduction of the new graphic engine HG2 in Matlab R2014b, things got pretty easy. One just needs to dig a little.
The color property now contains a forth value for opacity/transparency/face-alpha, so that's all you need to change:
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;
Even color gradients are nothing special anymore.
You can use the patchline submission from the File Exchange, in which you can manipulate line objects as if they were patch objects; i.e. assign them transparency (alpha) values.
Here is some sample code using the 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 output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With