Take the 2-minute tour ×

I have a matplotlib horizontal bar drawn as follows:

import matplotlib.pyplot as plt
from numpy import *
from scipy import *
bars = arange(5) + 0.1
vals = rand(5)
print bars, vals
plt.figure(figsize=(5,5), dpi=100)
spines = ["bottom"]
ax = plt.subplot(1, 1, 1)
for loc, spine in ax.spines.iteritems():
  if loc not in spines:
# don't draw ytick marks
plt.barh(bars, vals, align="center")

This produces this image:enter image description here

I wanted to only show the xaxis, which worked using spines, but now it plots these hanging tickmarks for the right-hand yaxis. How can I remove these? id like to keep the ytickmarks on the left hand side of the plot and make them face out (direction opposite to bars). I know that I can remove the ytickmarks altogether by uncommenting the line:


but i want to keep the ytick marks only on the left hand side. thank you.

EDIT: I achieved a solution after some trial and error though i'm sure my solution is probably not the best way to do it, so please let me know what you think still. i found that i can do:


to set the tick mark direction. to get rid of the right y-axis ticks, i use:

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

you could simply use:

ax.tick_params(axis='y', direction='out')

this will orientate the ticks as you want. And:


this will not plot the right ticks

share|improve this answer
add comment

Your Answer


