python - 能否在python或Matlab中用Pyplot绘制数字波形图?

标签 python matlab graph matplotlib

我正在尝试使用 python 中的 pyplot 为 01010101010101 等位绘制数字信号波形图,如

http://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Differential_manchester_encoding.svg/600px-Differential_manchester_encoding.svg.png

用 Pyplot 可以吗?

最佳答案

正如 tcaswell 所指出的,正确使用的函数是 step。这是一个近似于给定情节的示例:

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))

plt.hold(True)
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()

enter image description here

关于python - 能否在python或Matlab中用Pyplot绘制数字波形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20036161/

相关文章:

python - 避免嵌套 .apply()

matlab - 从每行中添加不同数量的元素

c# - 使用 C# 的动态图形(要保存为 PNG 格式)

Python 异常 "as"关键字

python - 将 jupyter notebook inlinebackend figsize 设置得更大

Matlab str2func 与现有工作区函数

matlab - 使用 fmincon ODE Matlab 进行优化

python /NetworkX : Add Weights to Edges by Frequency of Edge Occurance

graph - 我可以从包含图自动生成欧拉(维恩)图吗

python - 如何判断进程是否在 Windows 上的 Python 中响应