[英]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()
您必須將“角度”列轉換為度數。
下面是一個心形曲線的例子。 如果您將角度保持為度數:
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”代表“北”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.