线上标记
Markers on the Line
我有一个列表列表,由两个不同的数据组成,用于绘制 2 条线,另一个列表列表由这些各自线上的标记组成。但是标记列表的列表可以有空集。我写了一个代码,但它没有显示任何图像。谁能告诉我为什么以下几行不起作用?
import numpy as np
import matplotlib.pyplot as plt
def Draw(Narratives, Prob_failure):
x=list(range(0,len(Narratives[0])))
for i in range(len(Narratives)):
plt.figure(figsize=(12,8))
if not Prob_failure[i]:
plt.plot(x,Narratives[i])
else:
Int_Prob_failures = [int(x) for x in Prob_failure[i] ]
markers_on = Int_Prob_failures
plt.plot(x,Narratives[i],'-gD', markevery=markers_on)
plt.xlim(0,len(Narratives[0]))
plt.ylim(0.0, 2000.0)
plt.grid(True)
plt.xlabel('Length of the Data Narrative', fontsize=15)
plt.ylabel('Intervals', fontsize=15)
plt.title('Plotting Data Narratives', weight='bold')
plt.legend()
plt.show()
Data = [[40.495959999999997, 68.728006916094003, 80.991919999999993, 121.48787999999999, 161.98383999999999, 200.75514611468412, 202.47979999999998, 208.8702579527606, 242.97575999999998, 426.66599412223769, 598.13431735234519, 947.40769717700846], [40.495959999999997, 80.991919999999993, 121.48787999999999, 161.98383999999999, 202.47979999999998, 209.4165446035731, 242.97575999999998, 383.51736697098818, 451.56755438353258, 503.98594436505164, 516.26217431475163, 1099.3652534435903]]
Failures = [[68.728006916094003], []]
Draw(Data,Failures)
而不是:
Int_Prob_failures = [int(x) for x in Prob_failure[i] ]
markers_on = Int_Prob_failures
plt.plot(x,Narratives[i],'-gD', markevery=markers_on)
你可以试试:
index = []
for j in range(len(Prob_failure[i])):
for k in range(len(Narratives[i])):
if Prob_failure[i][j] == Narratives[i][k]:
index.append(k)
plt.plot(x,Narratives[i],'-gD', markevery = index )
markevery 选项采用您要强调的点的 index。
我有一个列表列表,由两个不同的数据组成,用于绘制 2 条线,另一个列表列表由这些各自线上的标记组成。但是标记列表的列表可以有空集。我写了一个代码,但它没有显示任何图像。谁能告诉我为什么以下几行不起作用?
import numpy as np
import matplotlib.pyplot as plt
def Draw(Narratives, Prob_failure):
x=list(range(0,len(Narratives[0])))
for i in range(len(Narratives)):
plt.figure(figsize=(12,8))
if not Prob_failure[i]:
plt.plot(x,Narratives[i])
else:
Int_Prob_failures = [int(x) for x in Prob_failure[i] ]
markers_on = Int_Prob_failures
plt.plot(x,Narratives[i],'-gD', markevery=markers_on)
plt.xlim(0,len(Narratives[0]))
plt.ylim(0.0, 2000.0)
plt.grid(True)
plt.xlabel('Length of the Data Narrative', fontsize=15)
plt.ylabel('Intervals', fontsize=15)
plt.title('Plotting Data Narratives', weight='bold')
plt.legend()
plt.show()
Data = [[40.495959999999997, 68.728006916094003, 80.991919999999993, 121.48787999999999, 161.98383999999999, 200.75514611468412, 202.47979999999998, 208.8702579527606, 242.97575999999998, 426.66599412223769, 598.13431735234519, 947.40769717700846], [40.495959999999997, 80.991919999999993, 121.48787999999999, 161.98383999999999, 202.47979999999998, 209.4165446035731, 242.97575999999998, 383.51736697098818, 451.56755438353258, 503.98594436505164, 516.26217431475163, 1099.3652534435903]]
Failures = [[68.728006916094003], []]
Draw(Data,Failures)
而不是:
Int_Prob_failures = [int(x) for x in Prob_failure[i] ]
markers_on = Int_Prob_failures
plt.plot(x,Narratives[i],'-gD', markevery=markers_on)
你可以试试:
index = []
for j in range(len(Prob_failure[i])):
for k in range(len(Narratives[i])):
if Prob_failure[i][j] == Narratives[i][k]:
index.append(k)
plt.plot(x,Narratives[i],'-gD', markevery = index )
markevery 选项采用您要强调的点的 index。