我试图绘制一个类似于this的图形:
为此,我用python编写了以下函数

def plot_graph_perf(dataset):

        #TODO: Give labels as power ranges in spaces of 1000

        plotter = ['0',
                        '1200000-10', '1200000-14', '1200000-18',
                        '1200000-2', '1200000-22', '1200000-26', '1200000-30',
                        '1200000-34', '1200000-38', '1200000-42', '1200000-46',
                        '1200000-6',
                        '1600000-10', '1600000-14',
                        '1600000-18', '1600000-2', '1600000-22',
                        '1600000-26', '1600000-30', '1600000-34',
                        '1600000-38', '1600000-42', '1600000-46',
                        '1600000-6',
                        '2000000-10', '2000000-14',
                        '2000000-18', '2000000-2', '2000000-22',
                        '2000000-26', '2000000-30', '2000000-34',
                        '2000000-38', '2000000-42', '2000000-46',
                        '2000000-6',
                        '2400000-10', '2400000-14',
                        '2400000-18', '2400000-2', '2400000-22',
                        '2400000-26', '2400000-30', '2400000-34',
                        '2400000-38', '2400000-42', '2400000-46',
                        '2400000-6' ,
                        '800000-10', '800000-14',
                        '800000-18', '800000-2', '800000-22',
                        '800000-26', '800000-30', '800000-34',
                        '800000-38', '800000-42', '800000-46',
                        '800000-6' ]


        x_axis_labels = dataset[1]

        x=[a for a in range(len(x_axis_labels))]
        y_axis_labels =  dataset[0]
        y=[a for a in range(len(y_axis_labels))]

        width = 0.1
        plt.figure
        plt.plot(plotter, color = 'g')
        plt.tight_layout(pad=1, h_pad=4, w_pad=None)
        plt.xticks(x,x_axis_labels, rotation='vertical')
        plt.yticks(y,y_axis_labels, rotation='horizontal')
        plt.xlabel('Power')
        plt.ylabel('perf')
        plt.title(file + ' | (Power)')
        fig = plt.gcf()
        fig.set_size_inches(28.5,10.5)
        plt.savefig('watt' + '.png',bbox_inches='tight', pad_inches=0.5,dpi=100)
        plt.clf()

其中数据集是二维列表,如下所示
dataset = [[],[]]

每个子列表包含与plotter相同数量的元素。
我将dataset[0]dataset[1]分别标绘为yx,但无法标绘plotter中的字符串值。
你能不能给我点启发,帮我在图上画出plotter的值。
谢谢。

最佳答案

必须分别为每个单词调用text函数:

words = list("abcdefg")
xs = np.random.randint(0,10,len(words))
ys = np.random.randint(0,10,len(words))

for x, y, s in zip(xs,ys,words):
    plt.text(x,y,s)

10-08 05:06