python - 隐藏刻度标签值但保留轴标签

标签 python matplotlib

我有这张图片:

plt.plot(sim_1['t'],sim_1['V'],'k')
plt.ylabel('V')
plt.xlabel('t')
plt.show()

enter image description here

我想隐藏数字;如果我使用:

plt.axis('off')

...我得到这张图片:

enter image description here

它还隐藏标签,Vt。如何在隐藏值的同时保留标签?

最佳答案

如果你使用 matplotlib object-oriented approach ,这是一个使用 ax.set_xticklabels() 的简单任务和 ax.set_yticklabels() .在这里,我们可以将它们设置为一个空列表以删除任何标签:

import matplotlib.pyplot as plt

# Create Figure and Axes instances
fig,ax = plt.subplots(1)

# Make your plot, set your axes labels
ax.plot(sim_1['t'],sim_1['V'],'k')
ax.set_ylabel('V')
ax.set_xlabel('t')

# Turn off tick labels
ax.set_yticklabels([])
ax.set_xticklabels([])

plt.show()

如果您还想删除刻度线和标签,可以使用 ax.set_xticks()ax.set_yticks()并将它们也设置为一个空列表:

ax.set_xticks([])
ax.set_yticks([])

关于python - 隐藏刻度标签值但保留轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37039685/

相关文章:

python - sklearn : sklearn. 数组的预处理 DeprecationWarning

python - 我如何重新格式化日期

python - 使用 seaborn 和 contourf,如何绘制网格线?

python - skimage 将 RGB 转换为 HSV 时如何获得正确的颜色。了解色调

Python - 一个图中的两个数字

python-3.x - 如何在 Seaborn 箱线图中调整 mustache 的大小?

python - 在 scikit-learn LinearRegression 中查找 p 值(显着性)

python - 如何将其中没有的列表转换为 torch.tensor()?

python - Matplotlib 使用宽右边距 - Python

python - Matplotlib : How to get a triangular matrix of subplots?