因此,我正在制作一个程序,读取多个二维列表,并将它们绘制为步进图函数。我想像这样并排打印出每一组图形(我把图形做成不同的颜色只是为了区分这两种颜色):
但是,我现在的代码使这两个集合相互重叠,如下所示:
我相信这可能与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()
您可以向
t
添加一些偏移量。你知道吗相关问题 更多 >
编程相关推荐