使用Matplotlib绘制时序图

2024-05-15 01:35:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想实现一个简单AND电路的时序图,它以a和B为输入,以C为输出,并带有任何时钟延迟。但我没有在这里或任何其他网站上遇到任何帮助我或提供任何线索的代码。我不知道如何解决这个问题。 python和matplotlib库中的新功能。我们将非常感谢任何帮助或建议。 谢谢


Tags: and代码功能matplotlib网站时钟建议电路
2条回答

找到了一些对你有帮助的链接

  1. Wavedrom Python包 https://pypi.org/project/wavedrom/

  2. Drawtime-时序图的编辑器和渲染器(在执行随机搜索时找到) 资料来源: https://github.com/max99x/drawtime

希望这有帮助

使用函数plt.step()

查看文档:https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.step.html

import matplotlib.pyplot as plt
import numpy as np

def my_lines(ax, pos, *args, **kwargs):
    if ax == 'x':
        for p in pos:
            plt.axvline(p, *args, **kwargs)
    else:
        for p in pos:
            plt.axhline(p, *args, **kwargs)

bits = [0,1,0,1,0,0,1,1,1,0,0,1,0]
data = np.repeat(bits, 2)
clock = 1 - np.arange(len(data)) % 2
manchester = 1 - np.logical_xor(clock, data)
t = 0.5 * np.arange(len(data))


my_lines('x', range(13), color='.5', linewidth=2)
my_lines('y', [0.5, 2, 4], color='.5', linewidth=2)
plt.step(t, clock + 4, 'r', linewidth = 2, where='post')
plt.step(t, data + 2, 'r', linewidth = 2, where='post')
plt.step(t, manchester, 'r', linewidth = 2, where='post')
plt.ylim([-1,6])

for tbit, bit in enumerate(bits):
    plt.text(tbit + 0.5, 1.5, str(bit))

plt.gca().axis('off')
plt.show()

相关问题 更多 >

    热门问题