How to get ticks "out" using mpl_toolkits.axes_grid.axislines ?

Hello,
I’m trying to get the ticks “out” in the following scripts using matplotlib svn version. Any reason why it’s not working ? Should I dig deeper in mpl_toolkits ?

– Script 1

modified from http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline3.html

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import Subplot
plt.rc(“xtick”, direction=“out”)
plt.rc(“ytick”, direction=“out”)
fig = plt.figure(1, (3,3))
ax = Subplot(fig, 111)
fig.add_subplot(ax)
ax.axis[“right”].set_visible(False)
ax.axis[“top”].set_visible(False)
plt.show()

– EOF

– Script 2

modified from http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline2.html

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import SubplotZero
import numpy as np
plt.rc(“xtick”, direction=“out”)
plt.rc(“ytick”, direction=“out”)

fig = plt.figure(1, (4,3))

a subplot with two additiona axis, “xzero” and “yzero”. “xzero” is

y=0 line, and “yzero” is x=0 line.

ax = SubplotZero(fig, 1, 1, 1)

fig.add_subplot(ax)

make xzero axis (horizontal axis line through y=0) visible.

ax.axis[“xzero”].set_visible(True)
ax.axis[“xzero”].label.set_text(“Axis Zero”)

make other axis (bottom, top, right) invisible.

for n in [“bottom”, “top”, “right”]:
ax.axis[n].set_visible(False)

xx = np.arange(0, 2*np.pi, 0.01)
ax.plot(xx, np.sin(xx))

plt.show()

– EOF

Thanks for your help.

Best regards,

···


Nicolas Pinto
Ph.D. Candidate, Brain & Computer Sciences
Massachusetts Institute of Technology, USA
http://web.mit.edu/pinto

Hi,

Thanks for reporting this.
The axes class in axes_grid toolkits uses different artists to render
ticks and ticklabels. And some of the features in the original
matplotlib won't work correctly, and the "tick direction" turned out
to be one of them.

However, I just committed a fix for this to the svn (r7292), so it
should work now.
So, please install mpl from the current svn again, and test it.
Unfortunately, while the ticks are rotated, the pad for tick labels
are not automatically adjusted.
Therefore, you may want to adjust it manually. e.g.,

ax.axis["left"].major_tick_pad = 10

I'll try to improve this in the future.

On the other hand, you may take a look at the recently added "spine"
support in the main matplotlib.

http://matplotlib.sourceforge.net/examples/pylab_examples/spine_placement_demo.html

If you use spine, than all the ticks & ticklabels feature in mpl will work.

Regards,

-JJ

···

On Thu, Jul 23, 2009 at 3:23 PM, Nicolas Pinto<nicolas.pinto@...287...> wrote:

Hello,

I'm trying to get the ticks "out" in the following scripts using matplotlib
svn version. Any reason why it's not working ? Should I dig deeper in
mpl_toolkits ?

# -- Script 1
# modified from
http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline3.html
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import Subplot

plt.rc("xtick", direction="out")
plt.rc("ytick", direction="out")

fig = plt.figure(1, (3,3))

ax = Subplot(fig, 111)
fig.add_subplot(ax)

ax.axis["right"].set_visible(False)
ax.axis["top"].set_visible(False)

plt.show()

# -- EOF

# -- Script 2
# modified from
http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline2.html

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import SubplotZero
import numpy as np

plt.rc("xtick", direction="out")
plt.rc("ytick", direction="out")

fig = plt.figure(1, (4,3))

# a subplot with two additiona axis, "xzero" and "yzero". "xzero" is
# y=0 line, and "yzero" is x=0 line.
ax = SubplotZero(fig, 1, 1, 1)
fig.add_subplot(ax)

# make xzero axis (horizontal axis line through y=0) visible.
ax.axis["xzero"].set_visible(True)
ax.axis["xzero"].label.set_text("Axis Zero")

# make other axis (bottom, top, right) invisible.
for n in ["bottom", "top", "right"]:
ax.axis[n].set_visible(False)

xx = np.arange(0, 2*np.pi, 0.01)
ax.plot(xx, np.sin(xx))

plt.show()

# -- EOF

Thanks for your help.

Best regards,

--
Nicolas Pinto
Ph.D. Candidate, Brain & Computer Sciences
Massachusetts Institute of Technology, USA
http://web.mit.edu/pinto

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks Jae-Joon, it’s working now. And thanks for pointing me to “spine”, that’s exactly what I was looking for!

Cheers,

N

···

On Thu, Jul 23, 2009 at 6:40 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Hi,

Thanks for reporting this.

The axes class in axes_grid toolkits uses different artists to render

ticks and ticklabels. And some of the features in the original

matplotlib won’t work correctly, and the “tick direction” turned out

to be one of them.

However, I just committed a fix for this to the svn (r7292), so it

should work now.

So, please install mpl from the current svn again, and test it.

Unfortunately, while the ticks are rotated, the pad for tick labels

are not automatically adjusted.

Therefore, you may want to adjust it manually. e.g.,

ax.axis[“left”].major_tick_pad = 10

I’ll try to improve this in the future.

On the other hand, you may take a look at the recently added “spine”

support in the main matplotlib.

http://matplotlib.sourceforge.net/examples/pylab_examples/spine_placement_demo.html

If you use spine, than all the ticks & ticklabels feature in mpl will work.

Regards,

-JJ

On Thu, Jul 23, 2009 at 3:23 PM, Nicolas Pinto<nicolas.pinto@…287…> wrote:

Hello,

I’m trying to get the ticks “out” in the following scripts using matplotlib

svn version. Any reason why it’s not working ? Should I dig deeper in

mpl_toolkits ?

– Script 1

modified from

http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline3.html

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid.axislines import Subplot

plt.rc(“xtick”, direction=“out”)

plt.rc(“ytick”, direction=“out”)

fig = plt.figure(1, (3,3))

ax = Subplot(fig, 111)

fig.add_subplot(ax)

ax.axis[“right”].set_visible(False)

ax.axis[“top”].set_visible(False)

plt.show()

– EOF

– Script 2

modified from

http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline2.html

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid.axislines import SubplotZero

import numpy as np

plt.rc(“xtick”, direction=“out”)

plt.rc(“ytick”, direction=“out”)

fig = plt.figure(1, (4,3))

a subplot with two additiona axis, “xzero” and “yzero”. “xzero” is

y=0 line, and “yzero” is x=0 line.

ax = SubplotZero(fig, 1, 1, 1)

fig.add_subplot(ax)

make xzero axis (horizontal axis line through y=0) visible.

ax.axis[“xzero”].set_visible(True)

ax.axis[“xzero”].label.set_text(“Axis Zero”)

make other axis (bottom, top, right) invisible.

for n in [“bottom”, “top”, “right”]:

ax.axis[n].set_visible(False)

xx = np.arange(0, 2*np.pi, 0.01)

ax.plot(xx, np.sin(xx))

plt.show()

– EOF

Thanks for your help.

Best regards,

Nicolas Pinto

Ph.D. Candidate, Brain & Computer Sciences

Massachusetts Institute of Technology, USA

http://web.mit.edu/pinto



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Nicolas Pinto
Ph.D. Candidate, Brain & Computer Sciences
Massachusetts Institute of Technology, USA
http://web.mit.edu/pinto