Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove x ticks but keep grid lines

I have a Pyplot plot, which I want to add gridlines to. I did this using:

plt.grid(True)

I then removed my x ticks using:

ax1.xaxis.set_visible(False)

My x ticks were removed, but so were the x grid lines. I would like them to stay.

Is there a way I can do this please?

like image 795
user1551817 Avatar asked Sep 17 '13 22:09

user1551817


People also ask

How do you remove the X axis from a tick?

To remove the ticks on the x-axis, tick_params() method accepts an attribute named bottom, and we can set its value to False and pass it as a parameter inside the tick_params() function. It removes the tick on the x-axis.

How do you change the tick frequency of a string X axis?

You can set the ticks using ax. set_xticks() . Here you can slice the x list to set a ticks at every 2nd entry using the slice notation [::2] . Then set the x tick labels using ax.


1 Answers

Try this:

plt.grid(True)
ax.xaxis.set_ticklabels([])

It should work. The grid will be intact, but there won't be any tick labels. If you don't want the ticks too, add:

ax.xaxis.set_ticks_position('none')
like image 69
Lucas Ribeiro Avatar answered Sep 20 '22 02:09

Lucas Ribeiro