matplotlib 如何将刻度设置为不可见但使刻度标签保持可见

vsdwdz23  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(306)

我将时钟嵌板绘制为:

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([])

它显示为:

我想将刻度设置为不可见,但标注保持可见,并尝试添加线ax.set_xticks([])
然后所有的刻度和刻度标签都消失。
如何将刻度设置为不可见,而使刻度标签保持可见?

iklwldmw

iklwldmw1#

您可以使用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()

输出:

注意:这也适用于ax.tick_params(grid_linestyle='')ax.tick_params(grid_linewidth=0)

相关问题