# How to plot a circle with polar coordinates in which the colour of the circle changes by data?

2 views (last 30 days)
Jani on 4 Nov 2021
Commented: DGM on 5 Nov 2021
Hi! I want to make something like this, which I found in an article.
In my work I model the drying of granulates, and the moisture content of the particles are changing in the function of time and the radius of the particle. I want to take some timesnaps and plot the moisture content of the particle which is changing with the radius, and next to them the colour bar explains what moisture content belongs to the colour.
So far modelled what I want in a 2D figure, in which I took five different timesnaps, but don't know how to plot like in the upper image.
I attached my code so you have my data. Thank you in advance!
x = linspace(0,0.0008,10);
t = linspace(0,200,50);
m = 0;
eqn = @(x,t,u,dudx) fluidPDE(x,t,u,dudx);
ic = @(x) fluidIC(x);
bc = @(xl,ul,xr,ur,t) fluidBC(xl,ul,xr,ur,t)
sol = pdepe(m,eqn,ic,bc,x,t);
u = sol(:,:,1);
surf(x,t,u)
title('Moisture content')
ylabel('Time [s]')
zlabel('Moisture content [-]')
figure
hold on
plot(x,u(5,:),'Linewidth',2)
plot(x,u(20,:),'Linewidth',2)
plot(x,u(30,:),'Linewidth',2)
plot(x,u(40,:),'Linewidth',2)
plot(x,u(end,:),'Linewidth',2)
legend('t=5 s','t=20 s','t=30 s','t=40 s','t=50 s')
ylabel('Moisture content [-]')
title('Moisture content')
function [c,f,s] = fluidPDE(x,t,u,dudx) % Equation to solve
D=3e-9
c = 1/D;
f = dudx;
s = 2/x;
end
% ----------------------------------------------------
function u0 = fluidIC(x) % Initial condition
X0=0.2
u0 = X0;
end
% ----------------------------------------------------
function [pl,ql,pr,qr] = fluidBC(xl,ul,xr,ur,t) % Boundary conditions
D=3e-9
rop=2500
k=1.8e-4
uf=0.05
pl = 0;
ql = 1;
pr = k*(ur-uf);
qr = D;
end

DGM on 5 Nov 2021
Edited: DGM on 5 Nov 2021
Something like this may suffice. It probably needs quite a bit of tweaking (labels, titles, geometry adjustment) still, but it's a start.
t = linspace(0,200,50);
m = 0;
eqn = @(x,t,u,dudx) fluidPDE(x,t,u,dudx);
ic = @(x) fluidIC(x);
bc = @(xl,ul,xr,ur,t) fluidBC(xl,ul,xr,ur,t);
sol = pdepe(m,eqn,ic,bc,x,t);
u = sol(:,:,1);
figure(1)
surf(x,t,u)
title('Moisture content')
ylabel('Time [s]')
zlabel('Moisture content [-]')
figure(2)
hold on
plot(x,u(5,:),'Linewidth',2)
plot(x,u(20,:),'Linewidth',2)
plot(x,u(30,:),'Linewidth',2)
plot(x,u(40,:),'Linewidth',2)
plot(x,u(end,:),'Linewidth',2)
legend('t=5 s','t=20 s','t=30 s','t=40 s','t=50 s')
ylabel('Moisture content [-]')
title('Moisture content')
% this is the new part
figure(3)
nth = 100;
th = linspace(0,2*pi,nth).';
xx = x.*cos(th);
yy = x.*sin(th);
timeindices = [5 20 30 40];
datarange = [min(u(timeindices,:),[],'all') max(u(timeindices,:),[],'all')];
px = ceil(sqrt(numel(timeindices)));
py = numel(timeindices)/px;
pidx = reshape(1:py*(px+1),px+1,py).';
for k = 1:numel(timeindices)
subplot(py,px+1,pidx(k))
pcolor(xx,yy,repmat(u(timeindices(k),:),[nth 1]));
caxis(datarange)
colormap(jet)
axis equal off
sprintf('time = %d sec',timeindices(k)));
end
ha = subplot(py,px+1,pidx(k+(1:2)));
hp = get(ha,'Position');
caxis(datarange)
colorbar('Position', hp.*[1 1 0.5 0.75] + [hp(3)*0.25 hp(4)*0.125 0 0])
axis off
function [c,f,s] = fluidPDE(x,t,u,dudx) % Equation to solve
D=3e-9;
c = 1/D;
f = dudx;
s = 2/x;
end
% ----------------------------------------------------
function u0 = fluidIC(x) % Initial condition
X0=0.2;
u0 = X0;
end
% ----------------------------------------------------
function [pl,ql,pr,qr] = fluidBC(xl,ul,xr,ur,t) % Boundary conditions
D=3e-9;
rop=2500;
k=1.8e-4;
uf=0.05;
pl = 0;
ql = 1;
pr = k*(ur-uf);
qr = D;
end
DGM on 5 Nov 2021
I modified it.

### Categories

Find more on Oil, Gas & Petrochemical in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by