Search code examples
pythonmatlabmatplotlibpolar-coordinates

How to plot Multiple Hysteresis loops on polar grid in Python/Matlab?


I want to plot multiple hysteresis loops on a polar grid either in Python or Matlab (like the image shown below-taken from a paper). I know how to use the polar plot function in matlab, but I am struggling with how to approach this problem, especially rescaling the hysteresis loops and how to define theta & rho so that each loop appears at the specific angle.

enter image description here


Solution

  • If You do NOT rely on graphics in one axes. Suppose we have two matrices HystX and HystY containing N rows each describing i-th hysteresis loop.

    polar(0,1.5)  % Hack to get 8 smaller
    hold on
    polar(1:0.1:2*pi(),abs(sin(1:0.1:2*pi()))) % Print the eight
    set(gcf,'units','centimeters')
    set(gca,'units','centimeters')
    
    AXpos=get(gca,'position')  % axes position
    AXCentre=[AXpos(1)+0.5*AXpos(3);AXpos(2)+0.5*AXpos(4)];
    Radius=min(AXpos(3:4));
    
    N=18;   % Number of hysteresis loops
    
    Theta=0:1/N:1-1/N;  % distribute Theta evenly
    Theta=2*pi()*Theta; % distribute Theta in range of (0,2Pi)
    
    % coordinates of centres of minor axes relative to major axes centre.
    axX=2/3*Radius*cos(Theta);
    axY=2/3*Radius*sin(Theta);
    
    % align the reference centre with centre of major axes, compensate dimensions of minor axes
    axX=axX+AXCentre(1)-0.5; % -0.5 for axes with width/height = 1
    axY=axY+AXCentre(2)-0.5;
    
    for ii=1:N
       MinorAX=axes('units','centimeters','position',[axX(ii),axY(ii),1,1])
       line=('xdata',HystX(ii,:),'ydata',HystY(ii,:),'parent',MinorAX(ii))
    end
    
    set(MinorAX,'visible','off')  %disappear minor axes;
    

    If You want to have everything in one axes You can use this example: In the first part I generate set of "hysteresis loops", then I plot the "8" in polar coordinates and finally I plot the hysteresis loops. This is based on the fact, that polar plot creates "fake axes" inside "real, hidden axes" (set(gca,'visible','on') will show them).

    close all;clear all;        % get rid off variables and figures
    N=12;                       % number of hysteresis loops
    HystX=zeros(N,100);         % X-values for loops
    HystY=HystX;                % Y-values for loops
    TempH=2*pi()*[0:0.01:1];    % Base for loops' content
    TempV=2*pi()*[0:1/N:1-1/N]; % Phase lead to differ the loops; position of the loop in axes
    %% Calclate the loops' cooordinates
    for ii=1:N
      for jj=1:101
        HystX(ii,jj)=0.1*cos(TempH(jj));
        HystY(ii,jj)=0.1*sin(TempH(jj)+TempV(ii));
      end
    end
    
    %% Plot the content oi polar axes
    polar(0,2)
    hold on
    polar(TempH,abs(sin(TempH)))
    % set(gca,'visible','on')
    
    %% Plot the hysteresis loops.
    for ii=1:12
      line('xdata',HystX(ii,:)+(1.5*cos(TempV(ii))),...
           'ydata',HystY(ii,:)+(1.5*sin(TempV(ii))))
    end