如何使用我的 df 中的列中的数据更改极坐标图投影 (seaborn.FacetGrid) 的度数?
How to change degrees in polar plot projection (seaborn.FacetGrid) with datas from a column in my df?
所以,基本上我试图绘制这个点云,其中不同的点集属于不同的给定“系列”(例如 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.
您必须将 'angle' 列转换为度数。
这里有一个心形曲线的例子。如果您将角度保持为度数:
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, 360, 100)
d = {'Angles': angle, '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, subplot_kws=dict(projection='polar'), height=5, sharex=False, sharey=False, despine=False)
g.map_dataframe(sns.scatterplot, x='Angles', y='Radius')
plt.show()
如果要改变原点的位置,在plt.show()
前加上即可
plt.gca().set_theta_zero_location("N")
此处 'N' 对应 'North'。
所以,基本上我试图绘制这个点云,其中不同的点集属于不同的给定“系列”(例如 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.
您必须将 'angle' 列转换为度数。
这里有一个心形曲线的例子。如果您将角度保持为度数:
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, 360, 100)
d = {'Angles': angle, '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, subplot_kws=dict(projection='polar'), height=5, sharex=False, sharey=False, despine=False)
g.map_dataframe(sns.scatterplot, x='Angles', y='Radius')
plt.show()
如果要改变原点的位置,在plt.show()
plt.gca().set_theta_zero_location("N")
此处 'N' 对应 'North'。