# XY MODEL COLOR MAP/PCOLOR

6 views (last 30 days)
Oliver Ford on 3 May 2021
Commented: Cris LaPierre on 3 May 2021
I have code that uses Wolff's Algorithm to simulate the XY Model in MATLAB and I want to implement a pcolor/color map to demonstrate each spin according to their angles across the system. But I want it to be live and changing as the angles change.
Any idea how to do this?
This is an example of how I want it to look https://i.stack.imgur.com/aSp7s.png
(UPDATE: I think I'm essentially looking to color the arrows based on their angle of spin with a color bar to the side.)

Cris LaPierre on 3 May 2021
This looks like the HSV colormap.
I'm not sure what you have for data, but first thought is to use imagesc.
% create a matrix of data
theta = linspace(0,2*pi);
data = sin(theta).*cos(theta')*3;
% view as an image
imagesc(data)
colormap hsv
caxis([-3 3])
colorbar
Another option is to create a surface
figure
surf(data,'EdgeColor','none')
view(2)
colormap hsv
caxis([-3 3])
colorbar
Cris LaPierre on 3 May 2021
I see your comment about just wanting to color the arrows. You create them using fill and plot, so you will have to look to what the acceptable inputs are for color for those functions.
The theta you point to is calculated once per iteration. You need the angle for every location in your X-Y grid. To use the image approach, you will need to build up a matrix of angles first, then use imagesc to view the matrix. A likely way to do this is to return the angle from the drawarrow function, and assign the value to a corresponding location in this matrix.