How set ticks invisible but leave tick-lables are visible

Question:

I plot a clock panel as:

import matplotlib.pyplot as plt
import numpy as np

# Create a polar coordinates
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, polar=True)

# set ticks and labels
angles = np.radians(np.linspace(0, 360, 12, endpoint=False))
labels = [str(l) for l in range(12)]
ax.set_xticks(angles, labels)
ax.set_yticks([])

It display as:

enter image description here

I want to set the ticks invisible but leave labels visible and tried adding line ax.set_xticks([])

Then all the ticks and tick-labels disappear.

How could I set ticks invisible but leave tick-labels visible?

Asked By: AbstProcDo

||

Answers:

You can make your ticks transparent with ax.tick_params(grid_alpha=0):

import matplotlib.pyplot as plt
import numpy as np

# Create a polar coordinates
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, polar=True)

# set ticks and labels
angles = np.radians(np.linspace(0, 360, 12, endpoint=False))
labels = [str(l) for l in range(12)]
ax.set_xticks(angles, labels)
ax.tick_params(grid_alpha=0)
ax.set_yticks([])

plt.show()

Output:

enter image description here

Note: this also works with ax.tick_params(grid_linestyle='') or ax.tick_params(grid_linewidth=0)

Answered By: Tranbi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.