Проблема в том, как функция метки должна знать, какой участок маркировать, если ему передан весь набор данных?!
Например, вы можете использовать pandas '.groupby
для циклического прохожденияуникальные цвета и создайте seaborn.regplot
для каждого из них.Тогда легко обозначить каждую ось индивидуально.
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(42)
import pandas as pd
import seaborn as sns
def label_point(df, ax):
for i, point in df.iterrows():
ax.annotate("{:.1f}".format(point['val']), xy = (point['x'], point['y']),
xytext=(2,-2), textcoords="offset points")
df = pd.DataFrame({"x": np.sort(np.random.rand(50)),
"y": np.cumsum(np.random.randn(50)),
"val" : np.random.randint(10,31, size=50),
"color" : np.random.randint(0,3,size=50 )})
colors = ["crimson", "indigo", "limegreen"]
fig, axes = plt.subplots(2,2, sharex=True, sharey=True)
for (c, grp), ax in zip(df.groupby("color"), axes.flat):
sns.regplot(x="x", y="y", data=grp, color=colors[c], ax=ax,
scatter_kws={"s": 25, "alpha": 1})
label_point(grp, ax)
axes.flatten()[-1].remove()
plt.show()
![enter image description here](https://i.stack.imgur.com/Rq1Bu.png)