3

I am looking for a means to add an additional axis pair, both tilted and origin displaced. They should be added to axes already used for displaying an image.

The result should look somehow close to

    y         x+y
    |\       /
  9 | + -2  + 18
    |  \   /
    |   \ /     
  8 |    x        
    |   / \
    |  /   \
  7 | + 14  \x-y
    |/       + 2
    +--------------------- x
    7    8    9             

(unfortunately I was not allowed to upload the actual Image that I created)

The center of the tilted axes should be localized at a certain coordinate (x0,y0), in my case (8,8), and I'd like to be able to treat the new axes like the normal axes, i.e use functions like set_xlabel, grid, etc. on them.

I was trying to get results using Affine2D transforms, floating axes and spines, but was unable to get the correct grip on this matter. Any help is greatly welcome.

The unimportant part of the image was done using

import numpy as np
import matplotlib.pyplot as plt

X = Y = np.linspace(7, 9, 100)
XX, YY = np.meshgrid(X,Y)
Z = np.exp(-(XX-XX.mean())**2/1 - (YY-YY.mean())**2/5)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(Z, origin='lower', extent=[X.min(), X.max(), Y.min(), Y.max()])
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid(True, color='white')

Thanks in advance.

1 Answers1

0

This is a difficult problem with matplotlib, and is similar to one that I have had in the past. I know that, with a substantial amount of spin up time, I believe it is possible to do what you are asking using floating axes.

I once opened a discussion about this on the matplotlib devel mailinglist http://old.nabble.com/Drawing-arbitrary-Axis-on-a-plot-p33625041.html but sadly nobody had any answers.

I will try to produce a working example of a floating axis, but don't know how successful I will be...

pelson
  • 21,252
  • 4
  • 92
  • 99
  • Thank you very much. That would be very kind. Indeed, a little later I stumbled across the package [pywcsgrid2](http://leejjoon.github.com/pywcsgrid2/users/overview.html#floating-axis) which apparently successfully deals with such floating axes for astronomical images. Unfortunately, this package seems tailored for processing certain astrophysics data and such requires some additional 'magic' to instantiate an axis. – user1551632 Jul 26 '12 at 08:01
  • Seems like the library you are referring to is using the floating axis artist in the mpl AxisArtist implementation. The limitation of that is that you have to specify a constant data value for the axis to follow (or so it seems). – pelson Jul 26 '12 at 08:07