2017-04-16 34 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