Python 无小数的轴值
我有一个matplotlib图,我正在绘制的数据总是参考0或1。我不希望x轴中有其他值Python 无小数的轴值,python,numbers,Python,Numbers,我有一个matplotlib图,我正在绘制的数据总是参考0或1。我不希望x轴中有其他值 #!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as tic import csv import numpy as np nq=['peter', 'mary', 'carol'] hist_q=[1,0,1] y_pos = np.arange(le
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as tic
import csv
import numpy as np
nq=['peter', 'mary', 'carol']
hist_q=[1,0,1]
y_pos = np.arange(len(hist_q))
plt.figure(1, [5, 20])
plt.ylim(-0.5,max(y_pos)+1)
plt.xlim(0,1)
plt.tick_params(axis='both', which='major')
plt.barh(y_pos, hist_q, align='center', alpha=0.3, label="Names")
plt.yticks(y_pos, nq)
plt.xlabel('Presence')
plt.legend(loc='upper right')
fig="s"
plt.savefig(fig,bbox_inches='tight')
plt.show()
fig = plt.figure()
fig.clf()
我猜你是想删除XTICK的数量。尝试在“savefig”之前将以下代码段插入到代码中
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
顺便说一句,numpy在您发布的代码中导入了两次