2017-04-16 33 views
1

我有一个列表,包含两个不同的数据,用于绘制两行,另一个列表包含这些行上的标记。但标记列表的列表可以有空集。我写了一段代码,但没有显示任何图像。谁能告诉我为什么以下几行不起作用?线上的标记

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) 
+1

你可以通过正确的缩进来调整你的代码......因为它现在很难读取 – Astrom

+0

@astrom,抱歉抱歉。我没有注意到。请挂在 –

+0

@Astrom,完成!谢谢 –

回答

1

相反的:

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选项需要要强调一点的指数

+0

很多人多谢谢@astrom –

+1

no pb!乐于帮助 – Astrom