Skip to content

Color on each branch of rootlocus #350

Description

@agustinvo

When using the rootlocus function the plot containing all the branches does not differentiate between branches. All of them are colored with the same blue.

I found a walkthrough for this, but you need to know well the transfer function you want to plot, like:
system=control.tf([1],np.convolve(np.polyadd(np.convolve([1,1],[1,1]),4),np.polyadd(np.convolve([1,3],[1,3]),4))) control.root_locus(system) plt.gca().get_lines()[1].set_color('b') plt.gca().get_lines()[2].set_color('r') plt.gca().get_lines()[3].set_color('g') plt.gca().get_lines()[4].set_color('m')

Where poles are the line [0], and the rest are the different branches. If you have zeros, then they are located in line[1], and the branches in [2],...

Is there any possibilty of colouring the different branches as MATLAB does?

Thank you for this module, I found it very useful!

Activity

  1. moorepants commented on Dec 5, 2019

    @moorepants

    I think you'd have to write a sorting routine for the computed eigenvalues because for each gain they may not be in the same order as the previous gain. For large steps between gains, I'm not sure if you can sort them, but for small gain steps you can for most cases. It isn't trivial for all bifurcation points though.

  2. agustinvo commented on Dec 5, 2019

    @agustinvo
    Author

    I think this issue is related with this line:

    # Now plot the loci
    for index, col in enumerate(mymat.T):
        ax.plot(real(col), imag(col), plotstr, label='rootlocus')`
    

    where col seems to be each branch. Indeed, if plotstr input is modified when running the command, all the branches are plotted similarly. Its default behaviour introduces:

    # Default values for module parameters
    _rlocus_defaults = {
        'rlocus.grid':True,
        'rlocus.plotstr':'b' if int(matplotlib.__version__[0]) == 1 else 'C0',
        'rlocus.PrintGain':True,
        'rlocus.Plot':True
    }
    

    I think setting that parameter free would color each branch separatelly. I will check later on.

  3. billtubbs commented on Aug 7, 2021

    @billtubbs
    Contributor

    I just tried this and it seems to work.

    Replaced:

        'rlocus.plotstr': 'b' if int(mpl.__version__[0]) == 1 else 'C0',
    

    with:

        'rlocus.plotstr': '' if int(mpl.__version__[0]) == 1 else '',
    

    Test script:

    system = control.tf([1], [1, 8, 30, 56, 65])
    control.root_locus(system)
    

    Result before:
    rlplot_python

    Result after:
    rlplot_python2

    Would be nice to change the colour of the crosses too.

  4. billtubbs commented on Aug 7, 2021

    @billtubbs
    Contributor

    I'm not sure what the benefit of the different colours is though. Without a legend or other way of knowing what each line is, what is the benefit?

  5. sawyerbfuller commented on Aug 7, 2021

    @sawyerbfuller
    Contributor
  6. billtubbs commented on Aug 8, 2021

    @billtubbs
    Contributor

    Here's a better example which illustrates the benefit of the coloured lines.

    rlplot_python4

  7. billtubbs commented on Aug 15, 2021

    @billtubbs
    Contributor

    One time when different colours per locus might be a bad idea, is when plotting the root loci of more than one system on the same plot. Is this actually useful or something that we want to support? If so, we could offer both options.

  8. sawyerbfuller commented on Aug 15, 2021

    @sawyerbfuller
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions