Thanks to visit codestin.com
Credit goes to github.com

Skip to content

x axis inverts when using plot with negative y #300

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

Closed
dewinkelwaar opened this issue Nov 1, 2021 · 4 comments
Closed

x axis inverts when using plot with negative y #300

dewinkelwaar opened this issue Nov 1, 2021 · 4 comments

Comments

@dewinkelwaar
Copy link

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.

@dewinkelwaar
Copy link
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()

@lukelbd
Copy link
Collaborator

lukelbd commented Nov 2, 2021

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.

@dewinkelwaar
Copy link
Author

Ok, I understand your point. Thanks for the reply

@lukelbd
Copy link
Collaborator

lukelbd commented Nov 3, 2021

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
Projects
None yet
Development

No branches or pull requests

2 participants