如何用我df中一列的数据改变极坐标投影的投影度seaborn.FacetGrid?

问题描述

所以,基本上,我试图绘制点云,其中不同的点集属于不同的给定“族”(例如k1,k2,k3,k4 ...)。结果还不错,但是直到现在,我仍然无法按照自己的意愿设置极坐标图的角度,即从我的数据框中给出度值,从而为各种数据集提供方向。可以这样做吗?

这是我尝试过的结果:

g = sns.FacetGrid(data_kn,hue='discontinuity set',subplot_kws=dict(projection='polar'),height=5,sharex=False,sharey=False,despine=False)

g.map_dataframe(sns.scatterplot,x='Dip direction (degrees)',y='Dip (degrees)')

g.add_legend()

plt.show()

as you can see the points are sparse throughout the polar countour,even if their 'radiant position' is right. Beyond this,it is impossible to see the points belonging to two sets.

解决方法

您必须将“角度”列转换为度。

这里是心形曲线的一个例子。如果您将角度保持为度:

import pandas as pd
import seaborn as sns 
import numpy as np
import matplotlib.pyplot as plt

##### Creating the dataframe
angle = np.linspace(0,360,100)
d = {'Angles': angle,'Radius': np.cos(np.pi*angle/180)*2 + 1}
df = pd.DataFrame(data=d)

### making the plot
g = sns.FacetGrid(df,subplot_kws=dict(projection='polar'),height=5,sharex=False,sharey=False,despine=False)
g.map_dataframe(sns.scatterplot,x='Angles',y='Radius')
plt.show()

enter image description here

但是如果您之前进行过转换:

import pandas as pd
import seaborn as sns 
import numpy as np
import matplotlib.pyplot as plt

### Creating the dataframe
angle = np.linspace(0,'Radius': np.cos(np.pi*angle/180)*2 + 1}
df = pd.DataFrame(data=d)


df['Angles'] = df['Angles']*np.pi/180 ### convert the angles into radiant

### Make the plot
g = sns.FacetGrid(df,y='Radius')
plt.show()

如果要更改原点的位置,只需在plt.show()

之前添加
plt.gca().set_theta_zero_location("N")

“ N”代表“北方”。

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...