Skip to content
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

inverted axis and box zoom #198

Open
ih64 opened this issue May 18, 2014 · 6 comments

Comments

Projects
None yet
7 participants
@ih64
Copy link

commented May 18, 2014

mpld3 is great and I've been having a lot of fun with it. I have a question about box zoom. Currently, I'm making some plots where the Y axis must be inverted (I'm plotting light curves in units of magnitude). I do this the traditional matplotlib way of doing ax.axes.invert_yaxis(). The plot renders fine. However, when I use the box zoom to zoom in on a certain part of my scatter plot, the Y axis switches to being uninverted again. Do you know if there is a way to for the axis to stay inverted?

Thanks!

@jakevdp jakevdp added the bug label May 18, 2014

@jakevdp

This comment has been minimized.

Copy link
Collaborator

commented May 18, 2014

That looks like a bug that will have to be fixed in the javascript side of things. I imagine that d3 automatically returns the box zoom limits sorted, and we need to detect when the axis is already inverted and flip those limits.

@vascotenner

This comment has been minimized.

Copy link

commented Aug 19, 2015

Related behaviour is present when zooming imshow plots. Here the DATA stays in place, but the Y-axis inverts.
Before zoom:
screenshot

After zoom:
screenshot-1

Notice that the red and blue box stay on the same coordinates, whereas the data stays at the same position.

@sjvdm

This comment has been minimized.

Copy link

commented Jul 14, 2016

+1 - same issue experienced with IMSHOW

@psalios

This comment has been minimized.

Copy link

commented Aug 6, 2016

+1 - same issue here. I am inverting both axis and when I zoom the scaling returns back to the initial order. Any help how to fix this?

@abast

This comment has been minimized.

Copy link

commented Oct 17, 2016

yup, some workaround in the meantime would be great :)

@aaronjmaxwell

This comment has been minimized.

Copy link

commented Jun 6, 2017

Has there been any motion on this? I'm using mpld3 version 0.3, and I've been having trouble with matplotlib.pyplot.imshow() of a numpy.histogram2d object. Using mpld3 on the figure does not register the origin = 'lower' keyword argument, so my image is flipped. The code snippet here was used to generate a .html and .png version of the images listed. Basically,

H, xe, ye = np.histogram2d(x, y, bins = 30)
ex = [xe[0], xe[-1], ye[0], ye[-1]]
fig, ax = plt.subplots()
ax.imshow(H.T, extent = ex, origin = 'lower')
ax.plot(x, y, '.', ms = 3, color = 'r')
plt.show()

yields:
lower
However, the same code using mpld3.show() will flip the image back (leaving the scatter points in the right spot):
upper
My workaround is to traverse the 2D matrix in the reverse direction along the column:

ax.imshow(H.T[::-1], extent = ex, origin = 'lower')

or else use:

ax.imshow(H.T, extent = ex, origin = 'upper')

However, the last one will only work if the plot axis already has the ~ax.ylim() set in the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.