Skip to content

plt.xlim won't work on limited range #340

Description

@limaries30

image

plt.xlim doesn;t work for me on tight range.
For example plt.xlim((0,1)) works well, but when I run with plt.xlim((-0.1,0.1)) the range won't change.

Any solutions?

Activity

  1. murrayrm commented on Oct 5, 2019

    @murrayrm
    Member

    I confirmed this behavior in the latest version of master, but not clear whether this is an issue with python-control or with matplotlib. If someone has time, perhaps see if you can show that it works correctly if you create that plot outside of python-control and then we can chase down what is going wrong (and in which package)?

    BTW, I tried calling plt.xlim() after plot.show() to see what happened and I got very strange results.

  2. zachsez commented on May 17, 2020

    @zachsez

    I don't have any issue, but then again I'm not sure I'm using all the right versions... How do I make sure the import control is the source/master fork I have instead of the released module I previously installed with pip.

  3. murrayrm commented on May 17, 2020

    @murrayrm
    Member
    import control
    print(control.__version__)
    

    The master branch should say something like 0.8.3.post16.

  4. zachsez commented on May 17, 2020

    @zachsez

    I got 0.8.1, just doubled checked and master is checkout at commit 03183d1

  5. murrayrm commented on May 17, 2020

    @murrayrm
    Member

    That's the latest commit for master, so it sounds like you are not picking up the latest version. Try pip uninstall control to get rid of the old version then run python setup.py install in the python-control source directory to install the latest version of master.

  6. zachsez commented on May 17, 2020

    @zachsez

    Ok I think its working now its says dev when I print the version thank you for the help. I am able to create the problem described above but when I create my own plot for the poles and zeros its works fine...

    plt.figure(2)
    X = [x.real for x in poles]
    Y = [x.imag for x in poles]
    W = [x.real for x in zeros]
    Z = [x.imag for x in zeros]
    plt.scatter(X, Y, s=50, marker='x', facecolors='red')
    plt.scatter(W, Z, s=50, marker='o', facecolors='blue')
    plt.xlim((-0.2, 0.2))
    plt.show()

    I'll keep digging!

  7. zachsez commented on May 19, 2020

    @zachsez

    So I think I figured it out, in grid.py in _final_setup plt.axis('equal') is called looking at the documentation here in order to maintain that equal aspect ratio the plot will may ignore xlim and ylim if it adjusts the figure out of an equal aspect ratio.

    Idea's:

    1. We could document this in our documentation.
    2. I could come up with logic similar to plt.axis('equal') which finds the max values of date and sets the limits to an equal limit to start but then allows for users to change the limits as they see fit.
  8. murrayrm commented on May 20, 2020

    @murrayrm
    Member

    We should definitely do the first (at a minimum), but the second is the preferred option, I think. There may also be a way to tell matplotlib to "relax" the rules for plt.axis("equal") that would allow rescaling of one of the axes.

  9. added this to the 0.9.x milestone on Dec 26, 2020
  10. removed this from the 0.9.1 milestone on Dec 31, 2021
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