问题描述
所以,基本上,我试图绘制点云,其中不同的点集属于不同的给定“族”(例如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()
解决方法
您必须将“角度”列转换为度。
这里是心形曲线的一个例子。如果您将角度保持为度:
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()
但是如果您之前进行过转换:
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”代表“北方”。