python - Weird inverted plot
问题描述
I'am working on a project and want to plot some Timing-Diagrams.
For some weird reason, for some inputs the plot is plotted inverted. Which means that zeros are plotted as one and ones are plotted as zero. This seems to be depending on line 11 and 12. If line 11 is uncommented the output is right and for line 12 vice versa.
I took a look into the array d
and except for the first 8 bit, they are the same.
Any suggestions?
from encdec8b10b import EncDec8B10B
import matplotlib.pyplot as plt
import numpy as np
second_level = 1.7
end = 50
#comma is 188
running_disp = 0
idle = list("0001111100")
#idle = list("1110000011")
print(idle)
#comma is 188
running_disp, comma = EncDec8B10B.enc_8b10b(188, 0, ctrl=1)
comma = list(f'{comma:010b}')
print(comma)
tx_bytes = [0xab, 0xcd, 0xef]
encoded_bits = list()
for b in tx_bytes:
running_disp, encoded = EncDec8B10B.enc_8b10b(b, running_disp)
encoded_bits += list(f'{encoded:010b}')
data = idle + comma + encoded_bits + [1]
d = np.repeat(data, 2)
clock = 1 - np.arange(len(d)) % 2
t = 0.5 * np.arange(len(clock))
for p in range(end+1):
plt.axvline(p, color='.5', linewidth=1)
for p in [0.01, second_level]:
plt.axhline(p, color='.5', linewidth=1)
plt.step(t, d, 'r', linewidth = 2, where='post')
plt.step(t, clock + second_level, 'r', linewidth = 2, where='post')
plt.ylim([0,3.3])
plt.xlim([0,end])
plt.yticks([0, 1, second_level, second_level+1], [0,1,0,1])
plt.xticks(np.arange(0,end+1,5))
plt.show()
解决方案
推荐阅读
- laravel-5 - 复数标签的语法
- svg - 在传单地图上显示 SVG
- ms-access - 用于更高版本 MS Access 的 Microsoft CommonDialog 控件
- paypal - Paypal 定期付款未收取费用
- jquery - 从另一个网页 jquery 显示模态
- angular - 如何包装primeng复选框标签的文本?
- python - 为什么在迭代 NumPy 数组时 Cython 比 Numba 慢得多?
- c# - 如何将 newPositions 距离设置为更接近原始小队成员位置?
- algorithm - 所有经过 2 点的路线的建议
- java - 在java中,我读到在实例化一个类时,它总是在堆上创建。这是否意味着实例化的对象是一个引用?