matplotlib中的文本绘制

2024-04-29 11:01:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图绘制一个类似于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是二维列表

^{pr2}$

每个子列表包含与plotter相同数量的元素。在

我将dataset[0]和{}分别绘制为y和{},但无法绘制plotter中的字符串值。在

你能不能帮我把plotter的值画出来。在

谢谢。在


Tags: inforlabelslenplot绘制rangeplt