Reputation: 223
I'm trying to plot sensor data, which was recorded with different angles.
import pandas as pd
import matplotlib.pyplot as plt
#create dataframe, each row contains an angle and a corresponding value
df = pd.DataFrame(columns = ["angle","value"])
df.angle = [0,5,10,15,20,25,30,35,40,45,50,55,60]
df['value'] = df.apply(lambda row: 100 -row.angle/2 , axis=1)
print(df)
#plotting
plt.polar(df['angle'].values,df['value'].values)
plt.show()
This returns:
But I need a plot that shows a value of 100 at zero degrees, 97.5 at 5 degrees and so on.
Upvotes: 5
Views: 3605
Reputation: 101
theta
in plt.polar(theta, r)
needs to be in radians. You can make a new column converting the angle to radians using the following:
import math
df['rad'] = df.apply(lambda row: row.angle*math.pi/180, axis=1)
plt.polar(df['rad'], df['value'])
This results in this plot:.
Upvotes: 5