Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
List 在matplotlib python中将数据标签放置在图形的某些位置_List_Function_Matplotlib_Dataset - Fatal编程技术网

List 在matplotlib python中将数据标签放置在图形的某些位置

List 在matplotlib python中将数据标签放置在图形的某些位置,list,function,matplotlib,dataset,List,Function,Matplotlib,Dataset,下面的数据集绘制了一个直线图,其中曲线在斜坡上为蓝色,在斜坡上为红色。我想为图形的颜色变化点添加数据标签。我想使用下面的代码将数据标签添加到我的当前代码中。数据标签用于打印当前位置的x、y坐标 用于添加数据标签的代码: label = f"({x},{y})" plt.annotate(label, # this is the text (x,y), # this is the point to label textco

下面的数据集绘制了一个直线图,其中曲线在斜坡上为蓝色,在斜坡上为红色。我想为图形的颜色变化点添加数据标签。我想使用下面的代码将数据标签添加到我的当前代码中。数据标签用于打印当前位置的x、y坐标

用于添加数据标签的代码:

label = f"({x},{y})"   
plt.annotate(label, # this is the text
            (x,y), # this is the point to label
             textcoords="offset points", # how to position the text
             xytext=(0,10), # distance from text to points (x,y)
             ha='center') # horizontal alignment can be left, right or center
现行代码

import matplotlib.pyplot as plt

x_long = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
L_Amount_list = [100.00, 9313.38, 43601.28, 61701.69, 74331.88, 198913.81, 153054.54, 119162.10, 74382.25, 203542.82, 160774.71, 220307.19, 366459.26]

colors = ['b' if a < b else 'r' for a,b in zip(L_Amount_list,L_Amount_list[1:])]      

for i in range(len(x_long)):
    try:
        plt.plot(x_long[i:i+2], L_Amount_list[i:i+2], color=colors[i])
    except:
        break
        
plt.show()
导入matplotlib.pyplot作为plt
x_long=[1,2,3,4,5,6,7,8,9,10,11,12,13]
贷款金额清单=[100.00、9313.38、43601.28、61701.69、74331.88、198913.81、153054.54、119162.10、74382.25、203542.82、160774.71、220307.19、366459.26]
颜色=['b'如果a

这里的
除了break
是个好主意吗?我会添加一些固定值,比如0或一个洞。另外,我对python了解不多,但我的想法是跟踪2个值,每当有蓝色变为红色或相反颜色时,就添加这对值。你在问一个新问题,逐字粘贴。我不介意你有一个新问题并提出一个问题,但你不需要有一个声誉或接受我的答案吗?对不起,忘记接受答案了,现在就做是
除了break
一个好主意吗?我会添加一些固定值,比如0或一个洞。另外,我对python了解不多,但我的想法是跟踪2个值,每当有蓝色变为红色或相反颜色时,就添加这对值。你在问一个新问题,逐字粘贴。我不介意你有一个新问题并提出一个问题,但你不需要有一个声誉或接受我的答案吗?对不起,忘记接受答案了,现在就做吧