Dalek
Dalek

Reputation: 4318

change the range of the intensity of a color based on a value between zero and one

How can I determine the intensity or ranging the darkness of a color based on probability distribution?

For instance in this code example

pgon1 = [-0.5 -0.6882;  0.5 -0.6882;  0.5 -1.6882;-0.5 -1.6882];
pgon2 = [0.5 -0.6882;  0.806 0.2629;  1.7571 -0.0431;1.4511 -0.9972];
pgon3 = [0.806 0.2629; 0 0.8507; 0.5878 1.6567;1.3938 1.0689];
pgon4 = [0 0.8507; -0.809 0.2629; -1.3968 1.1136;-0.5878 1.6597];
pgon5 = [ -0.809 0.2629; -0.5 -0.6882; -1.4511 -0.9972;-1.7601 -0.0461];
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1),'r')
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'k')
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'g')
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b')
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'m')
axis equal tight
view(3)
grid on

Can the intensity of black or blue be a function of some probability between zero and one?

Upvotes: 0

Views: 52

Answers (1)

Mansour Torabi
Mansour Torabi

Reputation: 421

There are two alternatives:

  1. It can be done using 'FaceColor' Property of the Patch object, with multiplying the RGB Triplet by some intensity value (according to your probabilities) , then you can adjust the darkness of a certain color:
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1)*1,'b','facecolor',0.20*[0, 0 1])
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'b','facecolor',0.30*[0, 0 1])
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'b','facecolor',0.50*[0, 0 1])
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b','facecolor',0.75*[0, 0 1])
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'b','facecolor',1   *[0, 0 1])

Pic1

OR

  1. By using the 'FaceAlpha' Property, you can adjust the transparency of a certain color according to your probability:
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1)*1,'b','facealpha',1)
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'b','facealpha',0.75)
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'b','facealpha',0.5)
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b','facealpha',0.3)
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'b','facealpha',0.2)

Pic2

Upvotes: 1

Related Questions