0
我玩弄在Python,我想創建一個發生在一個二維的清單,由1和0的每個列表中的一步圖形功能,以及各個曲線名單上的一個單獨的行,與此類似: clocking graph 要在圖中的線之間創造空間與階躍函數MatPlotLib
當我運行我的代碼,它看起來是這樣的:Code output
它可以是一個有點難以閱讀,尤其是在使用一個更大的時名單。我想在圖線之間創建空間以使其更具可讀性。任何幫助,將不勝感激。
# supress warning message
import warnings; warnings.simplefilter("ignore")
# extension libraries
import matplotlib.pyplot as plt
import numpy as np
bits = [[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
[0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1]]
for i in range(len(bits)):
data = np.repeat(bits[i], 2)
t = 0.5 * np.arange(len(data))
plt.hold(True)
plt.step(t, data + i, linewidth=1.5, where='post', color='g')
plt.ylim([-1, 10])
# Labels the graphs with binary sequence
for tbit, bit in enumerate(bits[i]):
plt.text(tbit + 0.2, i, str(bit), fontsize=12, color='g')
# removes the built in graph axes and prints line every interation
plt.gca().axis('off')
plt.show()