Rachayita Giri
Rachayita Giri

Reputation: 487

How to represent complex numbers corresponding to a single quantity in a polar plane?

I have a Python list in which each row contains two columns. The first column contains a real number (th) and the second column contains a complex number (voltage).

0.25  (1.2457255255383563e-09 - 7.827999559008199e-11j)
0.225 (1.2769209019868422e-09 - 1.1957504414521587e-10j)
0.2   (1.3221477572417824e-09 - 1.6359636324117563e-10j)
0.175 (1.382055160135606e-09  - 2.0572240011775488e-10j)
0.125 (1.5471711559849657e-09 - 2.696133396356665e-10j)
0.075 (1.787743723105496e-09  - 2.8204767576743745e-10j)
0.025 (2.0887332185896165e-09 - 2.0611142376588599e-10j)

I want to plot these voltages on a polar plane, labelled with their corresponding th values.

Using the following code, where data is the table I have shown above:

def th_polar_plots(data):
    th = []
    vreal = []
    vim = []
    for row in data:
        th.append(row[0])
        voltage = complex(row[1])
        vreal.append(voltage.real)
        vim.append(voltage.imag)
    plt.polar(th, vreal, 'ro-', th, vim, 'bo-')
    plt.show()

I am able to generate this: enter image description here

Not only is this incorrect, but it also fails to make any sense to me. Because what I need is each voltage vector with a dot/circle on it for the th value, since in the future I would need to plot more such th vs voltage tables in the same plane for comparison.

Edit: I have formatted the spacing and indentation in the table for better readability.

Upvotes: 0

Views: 225

Answers (1)

DrBwts
DrBwts

Reputation: 3657

Your radius is wrong in the plt.polar() call. Try the following in your code,

radius = np.sqrt(voltage.real**2 + voltage.imag**2)
plt.polar(th, radius, 'ro-')

Upvotes: 1

Related Questions