我正在尝试使用 FacetGrid 将相同的比较线添加到多个图中。这是我陷入困境的地方:
# Import the dataset
tips = sns.load_dataset("tips")
# Plot using FaceGrid, separated by smoke
g = sns.FacetGrid(tips, col="smoker", size=5, aspect=1.5)
g.map(plt.scatter, "tip", "total_bill")
x = np.arange(0, 50, .5)
y = 0.2*x
plt.plot(y, x, C='k')
plt.show()
这是结果
正如您所看到的,该线显示在最后一个图上,但不是第一个图上。我如何在两者上都获得它?
You can map
相同的功能FacetGrid
.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Import the dataset
tips = sns.load_dataset("tips")
# Plot using FaceGrid, separated by smoke
g = sns.FacetGrid(tips, col="smoker", height=5, aspect=1.5)
g.map(plt.scatter, "tip", "total_bill")
def const_line(*args, **kwargs):
x = np.arange(0, 50, .5)
y = 0.2*x
plt.plot(y, x, C='k')
g.map(const_line)
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)