我有一个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(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()
答案 0 :(得分:0)
我猜你试图删除xticks的数量。尝试在'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
BTW,numpy在您发布的代码中导入了两次。