2017-11-09 14 views
0

私は複数の2次元リストを読み込み、ステップグラフ関数としてプロットするプログラムを作成しています。私のコードは今、これらの二つのセットではなく、互いに重複せただしMatPlotLib互いに隣りの同じ行にグラフを印刷する

Desired Output

:私はそうのように並べてグラフ側の各セット(私はちょうど2つを区別するために、グラフに別の色をした)をプリントアウトしたいです、そのよう:

Actual Output

私はそれがplotPointsに私の「T」変数とは何かを持っているかもしれませんが、私は、私は何をする必要があるかを確認していないと信じています。どんな助けでも大歓迎です。

# supress warning message 
import warnings; warnings.simplefilter("ignore") 
# extension libraries 
import matplotlib.pyplot as plt 
import numpy as np 


def plotPoints(bits, color): 
    for i in range(len(bits)): 
     data = np.repeat(bits[i], 2) 
     t = 0.5 * np.arange(len(data)) 

     plt.step(t, data + i * 3, linewidth=1.5, where='post', color=color) 


     # Labels the graphs with binary sequence 
     for tbit, bit in enumerate(bits[i]): 
      plt.text(tbit + 0.3, 0.1 + i * 3, str(bit), fontsize=6, color=color) 


def main(): 

    plt.ylim([-1, 32]) 

    set1 = [[0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 1, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 0, 0, 0]] 
    set2 = [[1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 0, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 1, 1, 1]] 


    plotPoints(set1, 'g') 
    plotPoints(set2, 'b') 


    # removes the built in graph axes and prints line every interation 
    plt.gca().axis('off') 
    plt.ylim([-1, 10]) 


    plt.show() 

main() 

答えて

1

tにオフセットを追加できます。

import matplotlib.pyplot as plt 
import numpy as np 


def plotPoints(bits, color, offset=0): 
    for i in range(len(bits)): 
     data = np.repeat(bits[i], 2) 
     t = 0.5 * np.arange(len(data)) + offset 

     plt.step(t, data + i * 3, linewidth=1.5, where='post', color=color) 


     # Labels the graphs with binary sequence 
     for tbit, bit in enumerate(bits[i]): 
      plt.text(tbit + 0.3 +offset, 0.1 + i * 3, str(bit), fontsize=6, color=color) 


def main(): 

    set1 = [[0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 1, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 0, 0, 0]] 
    set2 = [[1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 0, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 1, 1, 1]] 


    plotPoints(set1, 'g') 
    plotPoints(set2, 'b', offset=len(set1[0])) 


    # removes the built in graph axes and prints line every interation 
    plt.gca().axis('off') 
    plt.ylim([-1, 10]) 


    plt.show() 

main() 

enter image description here

関連する問題