2017-03-25 10 views
0

グラフを作成して真理値の3つのリストを比較したいと思います。Pythonの真理値の水平グラフを作る方法

それがあれば、誰かが私に赤いマークグラフを作成する最も簡単な方法を教えてくださいすることができ、私は例

list1 = [True,False,True,True,True,False...] 

Plot example

ためのブール値(TrueとFalse)の3つの非常に長いリストを持っていますそれが偽であれば真、白または黒。

答えて

1
def morse(lists): 
    for i,list_ in enumerate(lists): 
     for j,value in enumerate(list_): 
      if value: 
       plt.plot([j,j+1],[i,i],'r',linewidth=5.0) 
    plt.axis([0,j+1,-1,i+1]) 
    labels=['List'+str(i) for i in range(1,len(lists)+1)] 
    plt.tick_params(
    axis='x',   # changes apply to the x-axis 
    which='both',  # both major and minor ticks are affected 
    bottom='off',  # ticks along the bottom edge are off 
    top='off',   # ticks along the top edge are off 
    labelbottom='off' 
    ) 
    plt.tick_params(
    axis='y',   # changes apply to the y-axis 
    which='minor',  # minor ticks are affected 
    left='off',  # ticks along the left edge are off 
    right='off'  # ticks along the right edge are off 
    ) 
    plt.xlabel('index') 
    plt.yticks(range(len(lists)),labels) 
    plt.show() 

import matplotlib.pyplot as plt 
morse([[True,False,True],[False,False,True]]) 

enter image description here

+0

ありがとうございました。横軸にリストのインデックスを追加するコードを更新してください。 例えば0,1,2,3,4,5,6 – HassanK

+0

'plt.xticks(range(len(lists [0])))')を追加し、 'which = 'both'を' which = 'minor '' x軸の – user4624500

+0

リストが大きすぎます(1000のインデックス)。どのように私はこれらのダニの間隔を表示できますか? (100番目のインデックスごとに)? – HassanK

関連する問題