首页 > 解决方案 > 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()

Line 11 is uncommented Line 12 is uncommented

标签: pythonnumpymatplotlibplot

解决方案


推荐阅读