Skip to content

How to change Root Locus plot color #789

Description

@AlHasanSony

The plot color of the roots seems like similiar while using rlocus function. Instead of showing the default color, we wanted to show different color.
So, how to change the color of the desired plot which used rlocus

Activity

  1. roryyorke commented on Nov 13, 2022

    @roryyorke
    Contributor

    This was already asked for in #350.

    For now, you can findobj the lines after plotting, and then set the colours:

    import numpy as np
    import matplotlib.pyplot as plt
    
    import control as ct
    
    # bit of a hack
    def findlines(artist):
        return (isinstance(artist, plt.Line2D)
                and artist.get_linestyle()=='-'
                and isinstance(artist.get_xdata(), np.ndarray))
    
    g = ct.tf([1],[1,1]) * ct.tf([1,3],[1,2]) * ct.tf([1],[1,1,16])
    
    ct.rlocus(g);
    
    h = plt.gca().findobj(match=findlines)
    
    for i, h_ in enumerate(h): h_.set_color(f'C{i}')
    
    plt.show()

    image

  2. locked and limited conversation to collaborators on Nov 27, 2022
  3. converted this issue into a discussion #803 on Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions