Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matplotlib中打印文本_Python_Matplotlib_Plot - Fatal编程技术网

Python 在matplotlib中打印文本

Python 在matplotlib中打印文本,python,matplotlib,plot,Python,Matplotlib,Plot,我试图绘制一个类似于以下内容的图表: 为此,我用python编写了以下函数 def plot_graph_perf(dataset): #TODO: Give labels as power ranges in spaces of 1000 plotter = ['0', '1200000-10', '1200000-14', '1200000-18', '1200

我试图绘制一个类似于以下内容的图表:

为此,我用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是这样的二维列表

dataset = [[],[]]
每个子列表包含与绘图仪相同数量的元素

我将
数据集[0]
数据集[1]
分别绘制为
y
x
,但无法在
绘图仪中绘制字符串值

你能帮我把
绘图仪的值画在图表上吗


谢谢。

您必须分别为每个单词调用
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)

您必须分别为每个单词调用
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)

你试过使用文本函数吗?是的,但我不知道应该给出哪三个参数。看起来像这样:这就是我试过的:
plt.text(x\u轴标签,y\u轴标签,绘图仪,fontsize=10)
我得到了错误:
TypeError:float()参数必须是字符串或数字
我应该迭代列表吗?是的,每次都必须单独调用
text
。您尝试过使用text函数吗?是的,但我不明白要给出哪三个参数。看起来像这样:这就是我尝试的:
plt.text(x\u轴标签,y\u轴标签,绘图仪,fontsize=10)
我得到了错误:
TypeError:float()参数必须是字符串或数字
我应该迭代列表吗?是的
text
每次都必须单独调用。谢谢!我已经做到了。但似乎还有另一个错误:ValueError:这一行的宽度和高度都必须低于32768:
plt.savefig('watt'+'.png',bbox_inches='tight',pad_inches=0.5,dpi=100)
谢谢!我已经做到了。但似乎还有另一个错误:ValueError:这一行的宽度和高度都必须低于32768:
plt.savefig('watt'+'.png',bbox_inches='tight',pad_inches=0.5,dpi=100)