2

我正在尝试绘制类似于的图表:

为此,我在 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]asyx,但无法在plotter.

您能否提供一些启示并帮助我plotter在图表上绘制值。

谢谢。

4

1 回答 1

4

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)

字母

于 2013-10-16T19:47:35.957 回答