3

I'm attempting to plot a color gradient which I would like to be uniform along an axis (in the case of the picture below defined by the angle pi/7)

When I use the patch command, The plot matches the desired gradient direction, but is not uniform along it (all sorts of triangles are formed between the points along the circle)

enter image description here

here is the code

N=120;
theta = linspace(-pi,pi,N+1);
theta = theta(1:end-1);
c = exp(-6*cos(theta-pi/7));
figure(1)
patch(cos(theta),sin(theta),c)
ylabel('y'); xlabel('x')
axis equal
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
jarhead
  • 1,821
  • 4
  • 26
  • 46

1 Answers1

5

You have to define the Facesproperty to make sure the colours fill stripes perpendicular to the axis (see Specifying Faces and Vertices) . Otherwise, MATLAB will use some algorithm to blend the colour as smoothly as it sees.

N=120;
a = pi/7;

theta = linspace(a,2*pi+a,N+1); % note that I changed the point sequence, this is just to make it easier to produce the matrix for Faces.
theta(end) = [];

ids = (1:N/2)';
faces = [ids, ids+1, N-ids, N-ids+1];

c = exp(-6*cos(a-theta))';

figure
patch('Faces', faces, 'Vertices',[cos(theta);sin(theta)]','FaceVertexCData',c, 'FaceColor', 'interp', 'EdgeColor', 'none')
ylabel('y'); xlabel('x')
axis equal

enter image description here

Anthony
  • 3,595
  • 2
  • 29
  • 38