Gonzalo
Gonzalo

Reputation: 1114

Remove x axis and y axis black lines with matplotlib

I am trying to remove the black lines from x axis and y axis and leave the labels (letters & numbers) but without success. I've done it for right and top side with the following code:

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

If I try for instance to use:

ax.axes.get_xaxis().set_visible(False)

it removes the labels but the black lines continue there. Any tip how could achieve this? I am trying to change a few graphs done with matplotlib to a more "clean" version. Thanks.

My graphs are like this one below:

enter image description here

Upvotes: 2

Views: 2438

Answers (2)

Mike Müller
Mike Müller

Reputation: 85482

You can make all spines invisible:

for spine in ax.spines.values():
    spine.set_visible(False)

Plus, as suggested by David:

ax.tick_params(axis=u'both', which=u'both',length=0)

Upvotes: 4

emmanuelsa
emmanuelsa

Reputation: 687

You should be able to set the colour of the edge to white like this

for edge_i in ['top', 'bottom', 'right', 'left']:
    ax.spines[edge_i].set_edgecolor("white")

I hope that helps

Upvotes: 2

Related Questions