隐藏轴值,但将轴刻度标签保留在matplotlib中 [英] Hide axis values but keep axis tick labels in matplotlib
本文介绍了隐藏轴值,但将轴刻度标签保留在matplotlib中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张图片:
plt.plot(sim_1['t'],sim_1['V'],'k')
plt.ylabel('V')
plt.xlabel('t')
plt.show()
我想隐藏数字;如果我使用:
I want to hide the numbers; if I use:
plt.axis('off')
...我得到这张图片:
...I get this image:
它还隐藏了标签,V
和 t
.隐藏值时如何保留标签?
It also hide the labels, V
and t
. How can I keep the labels while hiding the values?
推荐答案
如果使用matplotlib 面向对象的方法,这是使用 ax.set_xticklabels()
和 ax.set_yticklabels()
:
If you use the matplotlib object-oriented approach, this is a simple task using ax.set_xticklabels()
and 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()
这篇关于隐藏轴值,但将轴刻度标签保留在matplotlib中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文