Search code examples
matlabmatlab-figure

Increasing size of arrows in Nyquist plot?


Does anyone know how to increase the size of the arrows in the Nyquist plot generated by MATLAB Control System Toolbox (while keeping the line width and everything else in the figure the same)?


Solution

  • I noticed that you also asked the same question in MATLAB Central. Please make sure to refer other visitors to this answer if you found it useful.

    The Bad News first

    MATLAB Control System Toolbox provides the functions nyquist and nyquistplot to draw a Nyquist plot of the frequency response of a dynamic system model.

    Even though these functions allow a certain level of graphical customization (units, grids, labels and basic LineSpec), they don't allow to alter the size of the arrows that appear by default in the Nyquist plot (you can read more about this here and here).

    The Good News (time to hack!)

    I started exploring the object hierarchy of the Nyquist plot figure and realized that the arrows that are drawn are patch objects.

    How did I notice that?

    First I generated a sample Nyquist plot:

    sys = tf([2 5 1],[1 2 3]);    % System transfer function.
    nyquist(sys);                 % Nyquist plot.
    

    Nyquist plot with default arrows

    Then I ran a brute force test!

    The following test iterates through every graphics object of the Nyquist plot figure window and blinks one element in every iteration. This way I was able to visually identify the objects that were linked to the arrows, when they started blinking.

    h = findall(gcf);   % Find all graphics objects including hidden ones.
    t = 0.5;            % Time interval.
    
    for i = 1:length(h) % Loop through every object handle.
        disp(i);        % Display handle array index.
        pause(t);       % Pause for t seconds.
        status = h(i).Visible;      % Copy Visible property.
        if strcmp(status, 'on')     % If Visible = 'on' --> Visible = 'off'
            h(i).Visible = 'off';
        else                        % If Visible = 'off' --> Visible = 'on'
            h(i).Visible = 'on';
        end
        pause(t);               % Pause for t seconds.
        h(i).Visible = status;  % Restore original Visible property.
        pause(t);               % Pause for t seconds.
    end
    disp('Finished!');  % Display Finished!
    

    After running this test, I found out that h(196) and h(197) were the two arrows of the Nyquist plot, and they were patch objects.

    Changing the 'LineWidth' property was the next logical step. The following piece of code is really all you need to do in order to change the size of the arrows:

    sys = tf([2 5 1],[1 2 3]);    % System transfer function.
    nyquist(sys);                 % Nyquist plot.
    
    h = findall(gcf, 'Type', 'Patch');  % Find all patch objects.
    
    for i = 1:length(h)         % Loop through every patch object handle.
        h(i).LineWidth = 4;     % Set the new LineWidth value.
    end
    

    This is the result:

    Nyquist plot with larger arrows

    I hope that you enjoyed the adventure! :D