I am using the Seaborn to make a polar plot. here is my code:
r = np.linspace(0, 10, num=100)
df = pd.DataFrame({'r': r, 'rs': r})
df = pd.melt(df, id_vars=['r'], var_name='measure', value_name='theta')
g = sns.FacetGrid(df, col="measure", hue="measure",
subplot_kws=dict(projection='polar'), size=4,
sharex=False, sharey=False, despine=False)
g.map(plt.scatter, "theta", "r")
as you see the degrees are 0,45,90,... How can I change this interval?
Edit 1 : thanks to @Julio Daniel Reyes, the degrees problem has been solved but now I have another question: I need a line between points. I don't need dots here. I have checked the matplotlib
docs and I couldn't find a solution. I tried linewidths
but didn't worked for me in .scatter(x,y,linewidths)
I need something like this:
Edit 2 Since I changed my code like this:
ax = plt.subplot(111, polar=True)
ax.scatter(x=[radians(x) for x in df['degree'].values],
y=df['value'].values)
Replacing the scatter with plot, didn't worked for me!
Regards.
You can set the ticks with radians like this:
angle_ticks = np.multiply([0.5, 1.0, 1.5, 1.75, 2.0], np.pi)
g.set(xticks=angle_ticks)
Or if you prefer
n_ticks = 10
angle_ticks = np.linspace(0, 2 * np.pi, num=n_ticks + 1)[:-1]
g.set(xticks=angle_ticks)
Update 1: To get a line instead of dots you just need to replace plt.scatter
with plt.plot
like this:
g.map(plt.plot, "theta", "r")
Update 2: For your latest code:
ax.plot([radians(x) for x in df['degree'].values], df['value'].values)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.