如何在Seaborn图上绘制圆?

问题描述 投票:0回答:3

我有一个Seaborn Joinplot,我想在其上绘制一个空圆,该圆将标记(0,0)点周围的某个直径。像这样:enter image description here

如何完成?

python seaborn
3个回答
0
投票

我找到了答案:

a = sns.jointplot(x=var_x, y=var_y, data=my_df)

a.ax_joint.plot([0],[0],'o',ms=60 , mec='r', mfc='none',)

0
投票
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="white", color_codes=True)

tips = sns.load_dataset("tips")

a = sns.jointplot(x="total_bill", y="tip", data=tips)
a.ax_joint.plot([15],[3],'o',ms=60 , mec='r', mfc='none',)

0
投票

有一种肮脏的方法:根据等式生成圆,然后绘制圆。我敢肯定还有更复杂的解决方案,但我还不能弄清楚。通过修改sns.JointGrid的数据。

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

sns.set(style="ticks")

R = 8 # radius
d = np.linspace(0,2*np.pi, 400) # some data to draw circle

def circle(d, r):
    # x and y from the equation of a circle
    return r*np.cos(d), r*np.sin(d)


rs = np.random.RandomState(11)
x = rs.gamma(2, size=1000)
y = -.5 * x + rs.normal(size=1000)

#graph your data
graph = sns.jointplot(x, y, kind="hex", color="#4CB391")

# creating the circle
a, b = circle(d, R)

#graphing it
graph.x = a
graph.y = b
graph.plot_joint(plt.plot)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.