Python Matplotlib字符串xticks

Python Matplotlib字符串xticks,python,matplotlib,Python,Matplotlib,使用上面编写的代码,我无法将xticks绘制为每个条的字符串/浮点值。我做错了什么?ax.set\xticklabels(标签)应该可以正常工作。您缺少的是使用ax.set\u xticks(float)命令建立x记号 下面是一个例子: def plot_freq_error(diff,file,possible_frequency): for foo in range(0, len(diff)): x = [diff[foo]] name = comp

使用上面编写的代码,我无法将
xticks
绘制为每个条的字符串/浮点值。我做错了什么?

ax.set\xticklabels(标签)
应该可以正常工作。您缺少的是使用
ax.set\u xticks(float)
命令建立x记号

下面是一个例子:

def plot_freq_error(diff,file,possible_frequency):
    for foo in range(0, len(diff)):
        x = [diff[foo]]
        name = comp
        color = ['0.1', '0.2', '0.3','0.4','0.5','0.6','0.7','0.8', '0.9','0.95','1.0']
        label = ['0.8GHz','1.0GHz','1.2GHz','1.4GHz','1.6GHz','1.8GHz','2.0GHz','2.2GHz','2.4GHz']
        y = zip(*x)
        pos = np.arange(len(x))
        width = 1. / (1 + len(x))

        fig,ax = plt.subplots()
        matplotlib.rcParams.update({'font.size': 22})
        for idx, (serie, color,label) in enumerate(zip(y, color,label)):
            ax.bar(pos + idx * width, serie, width, color=color,label=label)

        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
        plt.tick_params(axis='both', which='major', labelsize=10)
        plt.tick_params(axis='both', which='minor', labelsize=8)
        plt.ylabel(name[foo],fontsize=40)
        #ax.legend(prop={'size':5})
        plt.xticks(label)
        plt.gray()
        plt.show()
        plt.clf()
ax.set\xticklabels(标签)
实际上应该可以工作。您缺少的是使用
ax.set\u xticks(float)
命令建立x记号

下面是一个例子:

def plot_freq_error(diff,file,possible_frequency):
    for foo in range(0, len(diff)):
        x = [diff[foo]]
        name = comp
        color = ['0.1', '0.2', '0.3','0.4','0.5','0.6','0.7','0.8', '0.9','0.95','1.0']
        label = ['0.8GHz','1.0GHz','1.2GHz','1.4GHz','1.6GHz','1.8GHz','2.0GHz','2.2GHz','2.4GHz']
        y = zip(*x)
        pos = np.arange(len(x))
        width = 1. / (1 + len(x))

        fig,ax = plt.subplots()
        matplotlib.rcParams.update({'font.size': 22})
        for idx, (serie, color,label) in enumerate(zip(y, color,label)):
            ax.bar(pos + idx * width, serie, width, color=color,label=label)

        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
        plt.tick_params(axis='both', which='major', labelsize=10)
        plt.tick_params(axis='both', which='minor', labelsize=8)
        plt.ylabel(name[foo],fontsize=40)
        #ax.legend(prop={'size':5})
        plt.xticks(label)
        plt.gray()
        plt.show()
        plt.clf()

您需要使用我尝试过的
ax.setxticklabels(label)
但似乎不起作用。您需要显示错误消息,而不是“似乎不起作用”。没有错误,xtick没有绘制,仅此而已。好吧,您似乎正在将它们设置为
关闭,在
底部='off',顶部='off'中,…
您需要使用我确实尝试过的
ax.setxticklabels(label)
但这似乎不起作用。您需要显示您收到的错误消息没有错误,xtick没有打印,仅此而已。好吧,似乎您正在
底部class='off',顶部class='off'中将它们设置为
关闭,…