Skip to content

Color on each branch of rootlocus #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
agustinvo opened this issue Dec 5, 2019 · 8 comments
Open

Color on each branch of rootlocus #350

agustinvo opened this issue Dec 5, 2019 · 8 comments

Comments

@agustinvo
Copy link

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!

@moorepants
Copy link

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.

@agustinvo
Copy link
Author

agustinvo commented Dec 5, 2019

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.

@billtubbs
Copy link
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.

@billtubbs
Copy link
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?

@sawyerbfuller
Copy link
Contributor

sawyerbfuller commented Aug 7, 2021 via email

@billtubbs
Copy link
Contributor

billtubbs commented Aug 8, 2021

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

rlplot_python4

@billtubbs
Copy link
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.

@sawyerbfuller
Copy link
Contributor

sawyerbfuller commented Aug 15, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants