Skip to content

x axis inverts when using plot with negative y #300

Closed

Description

@dewinkelwaar

Description

within cartesian grid, using plot, x axis inverts with y set starting with nagative number

Steps to reproduce

import numpy as np
import proplot as pplt

print(pplt.version)

fig = pplt.figure(suptitle='test')
ax = fig.subplot(111, title="A-B")

ax.format(xlim=(-2, 2),
xticks=0.5,
xloc=('data', -2),
xlabel='x axis',
xlabelloc='bottom',
ylim=(-2, 2),
yticks=0.5,
yloc=('data', -2),
ylabel='y axis')

ax.set_aspect('equal')

ax.scatter(-1, 1, color="b")
ax.text(-1, 1, "A")
ax.scatter(1, -1, color="b")
ax.text(1, -1, "B")

x_set = [-1, 1]
y_set = [1, -1]

ax.plot(x_set, y_set, color="r")
pplt.show()

Expected behavior:

The above code gives a grid as expected, with the 2 points A and B and a red line between them
image

Actual behavior: [What actually happened]

However, when changing the x_set/y_set lines to

x_set = [1, -1]
y_set = [-1, 1]

the x-axis inverts (i.e. the whole grid) starting with x = 2 going to x = -2

image

Equivalent steps in matplotlib

with ax.invert_xaxis() the grid inverts to the presentation as expected

Proplot version 0.9.5

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

Activity

  1. dewinkelwaar commented on Nov 2, 2021

    @dewinkelwaar
    Author

    Note that this issue doesn`t occur when using matplotlib

    import numpy as np
    import matplotlib.pyplot as plt

    fig = plt.figure()

    ax = plt.subplot()
    ax.set_xlim(-2, 2)
    ax.set_ylim(-2, 2)
    ax.set_title('line plot A->B vs B->A')

    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')

    ax.scatter(-1, 1, color="b")
    ax.text(-1, 1, "A")
    ax.scatter(1, -1, color="b")
    ax.text(1, -1, "B")

    #x_set = [-1, 1]
    #y_set = [1, -1]

    x_set = [1, -1]
    y_set = [-1, 1]

    ax.plot(x_set, y_set, color="r")
    pplt.show()

  2. lukelbd commented on Nov 2, 2021

    @lukelbd
    Collaborator

    This is part of the "standardized arguments" feature (see this link)... but unfortunately I did not document it! I'll add this to the docs in the next version.

    I find that most of the time, when I have "reversed" dependent variable coordinates, I want that axis to be reversed too. So I think I'd prefer to keep this default behavior. In your example, you can use ax.format(xreverse=False) to reverse the axis back. Alternatively (this is currently not part of the public API) ax.plot(x_set, y_set, autoreverse=False) should also work. Might make that part of the public API in the future.

  3. dewinkelwaar commented on Nov 3, 2021

    @dewinkelwaar
    Author

    Ok, I understand your point. Thanks for the reply

  4. added a commit that references this issue on Nov 3, 2021
    f34c12c
  5. lukelbd commented on Nov 3, 2021

    @lukelbd
    Collaborator

    No problem. FYI the master branch now includes documentation on auto-reversing in the "1D plotting" and "2D plotting" sections, and auto-reversing is now automatically disabled whenever the axis limits were previously explicitly fixed with e.g. ax.format(xlim=xlim) or ax.set_xlim(xlim) (f34c12c).

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