Python极坐标图:绘制与角度对应的值 [英] Python polar plot: Plot values corresponding to the angle

查看:57
本文介绍了Python极坐标图:绘制与角度对应的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制传感器数据,这些数据是用不同角度记录的.

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()

返回:

但是我需要一个绘图,在0度时显示100,在5度时显示97.5,依此类推.

But I need a plot that shows a value of 100 at zero degrees, 97.5 at 5 degrees and so on.

推荐答案

thetaplt.polar(theta, r) 需要以弧度为单位.您可以使用以下方法创建一个新列,将角度转换为弧度:

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'])

这将导致以下情节:.

这篇关于Python极坐标图:绘制与角度对应的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆