简体   繁体   中英

How to connect coordinates in Polar plot matplotlib

Currently I'm plotting coordinates in a polar plot using an array of angles with values. I have a text file:

[angle] [value]
0 54.3
5 54.4
10 54.2
15 54.4
20 54.6
25 54.4
30 54.2
35 54.4

I'm plotting like this:

import matplotlib.pyplot as plt

#Define arrays
angles=list()
values=list()
lines = [line.rstrip('\n') for line in open('values.txt')]
for line in lines: # Iterate lines
    stringElement = str.split(line, " ") # Split elements
    angle = int(stringElement[0])
    value = float(stringElement[1])

    angles.append(angle)
    values.append(value)

# Plot values
ax = plt.subplot(111, projection='polar')

#Plot dots
plt.polar(angles, values, 'k.', zorder=3)

#Plot lines
#plt.polar(angles, values)

ax.grid(True)
plt.show()

This looks like this: 点云

When I enable the lines, it should connect the dots to the closest neighbor, but connects to other lines instead. This looks like this:

在此处输入图片说明

How to connect the dots to the closest neighbor instead?

As @Arndt Jonasson pointed out, even though the polar plot displays everything in degrees, it expects the angles in radians. Now it works as it should

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM