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

Skip to content

axis limits come out reversed a lot #334

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
beckermr opened this issue Feb 3, 2022 · 5 comments
Closed

axis limits come out reversed a lot #334

beckermr opened this issue Feb 3, 2022 · 5 comments
Labels

Comments

@beckermr
Copy link

beckermr commented Feb 3, 2022

Description

Right now in many cases, the plot limits come out reverse (e.g., the x-axis goes from 1 to -4 instead of -4 to 1).

Steps to reproduce

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.

import proplot as pplt
import numpy as np

rng = np.random.RandomState(seed=10)
x = rng.uniform(size=1000)*4 - 6
y = rng.uniform(size=1000)*2 + 6

fig, axs = pplt.subplots()
axs.hexbin(x, y)

Expected behavior: axis limits numerically ordered (should be -6 to -2)

Actual behavior: came out reversed (-2 to -6)

Equivalent steps in matplotlib

Please try to make sure this bug is related to a proplot-specific feature. If you're not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.

import matplotlib.pyplot as plt
import numpy as np

rng = np.random.RandomState(seed=10)
x = rng.uniform(size=1000)*4 - 6
y = rng.uniform(size=1000)*2 + 6

fig, axs = plt.subplots(nrows=1, ncols=1)
axs.hexbin(x, y)

Proplot version

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

3.5.0
0.9.5

@lukelbd
Copy link
Collaborator

lukelbd commented Feb 3, 2022

This is related to #300 (also documented on this page). Proplot automatically reverses the axis when it detect "dependent" variable coordinates and the axes were not previously fixed -- however this behavior should definitely be disabled for hexbin and hist2d, and it looks like this used to be disabled for hist and histh but the #191 fix is now obsolete. Sorry for the annoying behavior! I'll fix this later today.

Note also that the #300 fix make this feature more conservative; for example when passing stuff to ax.plot(x, y) an axis will only be reversed if 1) the x limits were not previously fixed with e.g. set_xlim and 2) the x coordinates are monotonically decreasing rather than simply having a negative initial step size.

@lukelbd lukelbd added the bug label Feb 3, 2022
@beckermr
Copy link
Author

beckermr commented Feb 3, 2022

Thank you!

@lukelbd lukelbd closed this as completed in 275bf30 Feb 3, 2022
@lukelbd
Copy link
Collaborator

lukelbd commented Feb 3, 2022

Fixed by 275bf30. Here's an example:

fig, axs = pplt.subplots(ncols=2, share=False)
x = np.sort(np.random.rand(100) * 100)
x = x[::-1]
axs[0].hist(x)
axs[1].hexbin(x, x)
print(pplt.internals.inputs._is_descending(x))

Result is True but axes are not reversed:

iTerm2 dtQmy4

@beckermr
Copy link
Author

beckermr commented Feb 3, 2022

Thank you! Looking forward to a release with the patch!

@esheldon
Copy link

I'm still seeing this for the quiver command, even in new releases, does that need to be addressed separately?

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

No branches or pull requests

3 participants