Home > Enterprise >  real and imaginary plot
real and imaginary plot

Time:03-29

I have an complex array (x iy). I am using the codes below to plot the real part of my array, however this ends of plot nothing except a white grid :|

plt.plot(t.reshape(1,-1),initgate.real)
plt.show()

t is an aray looks like this: [-128,-127,...0,...127,128] and initgate is an array like this: [[0.70521068-0.70899781j, 0.46305858-0.88632768j, 0.13136362-0.99133425j, 0.72999357-0.68345401j, 0.01607073-0.99987086j, 0.82185338-0.56969906j,....]]

thanks.

CodePudding user response:

I think the problem is that you have your imaginary array in an array. You are running the .real function on an array of arrays, instead of on an array of imaginary numbers. I believe simply removing the outer array will solve your problems. For example:

t = np.arange(-128,129)
initgate = [np.random.rand(len(t))   np.random.rand(len(t))*1j]
real = initgate[0].real
imag = initgate[0].imag
plt.plot(t,real)
plt.show()
  • Related