How to fill the area between two curves on a polar plot?
Afficher commentaires plus anciens
My code looks is below. I attached the two curves it generates, with the data that I have. How can I fill the space between the two curves?
t=data(1,:);
a1=data(11,:);
b1=data(12,:);
r_scale=50;
line_width=2;
font_size=12;
marker = 3;
figure(1)
polarplot(t,a1,'-or','MarkerSize',2)
hold on
polarplot(t,b1,'-ok','MarkerSize',2)
hold on
Réponse acceptée
Plus de réponses (2)
Nate Roberts
le 27 Oct 2021
Modifié(e) : Nate Roberts
le 28 Oct 2021
I wrote a function that overlays a transparent cartesian axis over the polar axis. This may be cheating a little bit, but it gets the job done and looks nice:
theta = linspace(0,2*pi,180);
rho = 10*ones(size(theta));
f = figure('Color','White');
p = polarplot(theta,rho); rlim([0,15]);
polarfill(gca,theta,rho-normrnd(2,0.2,size(rho)),rho+normrnd(2,0.2,size(rho)),'blue',0.6)
function polarfill(ax_polar,theta,rlow,rhigh,color,alpha)
ax_cart = axes();
ax_cart.Position = ax_polar.Position;
[xl,yl] = pol2cart(theta,rlow);
[xh,yh] = pol2cart(fliplr(theta),fliplr(rhigh));
fill([xl,xh],[yl,yh],color,'FaceAlpha',alpha,'EdgeAlpha',0);
xlim(ax_cart,[-max(get(ax_polar,'RLim')),max(get(ax_polar,'RLim'))]);
ylim(ax_cart,[-max(get(ax_polar,'RLim')),max(get(ax_polar,'RLim'))]);
axis square; set(ax_cart,'visible','off');
end
See also my answer to a similar question. It is a more general solution than the one posted here: https://www.mathworks.com/matlabcentral/answers/325599-fill-area-between-two-polar-curves#answer_818408
1 commentaire
Arthur Vieira
le 20 Juin 2022
This solution seems nice but causes me issues. 1. I can't for instance save the figure as doing so will save the figure with just the fill in a cartesian axis. Can only take pictures with PrintScreen. 2. I can't 'hold on' after the fill has been added to plot more stuff. I'd actually like to plot two lines and two fills in the same figure.
Walter Roberson
le 18 Mai 2017
0 votes
Unfortunately that does not appear to be possible. surface() and patch() specifically reject being children of PolarAxes; and fill() and area() and mesh() [none of which are primitives] fail when calling newplot() with newplot() rejecting making a cartesian child of a polar axes.
The actual drawing of polarplot() is by calling plot(), the implementation of which is now private.
3 commentaires
Benjamin Cowen
le 18 Mai 2017
Modifié(e) : Walter Roberson
le 18 Mai 2017
Walter Roberson
le 18 Mai 2017
That code works by not using a polarplot() with its polaraxes(): it expects the user to use polar() which uses cartesian axes underneath it, and then it use patch() with cartesian coordinates.
Benjamin Cowen
le 18 Mai 2017
Catégories
En savoir plus sur Polar Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

