ely
ely

Reputation: 505

Restore left ticks in matplotlib

I have a question similar to: Python Matplotlib Y-Axis ticks on Right Side of Plot

I fixed the problem of putting y-axis ticklabels on the right side of the plot, but I would like to restore y ticks on the left side too.

I tried with:

yax.set_ticks_position('both')

but I get:

ax0.set_ticks_position('both')
AttributeError: 'AxesSubplot' object has no attribute 'set_ticks_position'

How can I solve this problem?

Upvotes: 1

Views: 1482

Answers (2)

tiago
tiago

Reputation: 23502

You are not getting the right object on which to call set_ticks_position(). Here's a simpler way with gca():

from pylab import *

figure()
plot(arange(5))
ax = gca()
ax.yaxis.tick_right()
ax.yaxis.set_ticks_position('both')

enter image description here

Upvotes: 2

Robbert
Robbert

Reputation: 2724

In the second code sample you use ax0, which I guess is an Axes instance, in the first code sample you use yax, which presumably the axis-child of ax0.

I think you're looking for tick_params: ax0.tick_params(axis = 'y', direction = 'in')

Upvotes: 1

Related Questions