From 24789565a5f1c59808954dfc2f4e0b8c4604ce1d Mon Sep 17 00:00:00 2001 From: Maoz Gelbart <13831112+MaozGelbart@users.noreply.github.com> Date: Tue, 12 May 2020 00:05:04 +0300 Subject: [PATCH] use scatterplot instead of plt.scatter --- seaborn/axisgrid.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 07763effc0..7b2ab817de 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -516,7 +516,7 @@ def __init__( :context: close-figs >>> g = sns.FacetGrid(tips, col="time", row="smoker") - >>> g = g.map(plt.scatter, "total_bill", "tip", edgecolor="w") + >>> g = g.map(sns.scatterplot, "total_bill", "tip") Assign one of the variables to the color of the plot elements: @@ -524,7 +524,7 @@ def __init__( :context: close-figs >>> g = sns.FacetGrid(tips, col="time", hue="smoker") - >>> g = (g.map(plt.scatter, "total_bill", "tip", edgecolor="w") + >>> g = (g.map(sns.scatterplot, "total_bill", "tip") ... .add_legend()) Change the height and aspect ratio of each facet: @@ -548,10 +548,10 @@ def __init__( .. plot:: :context: close-figs - >>> kws = dict(s=50, linewidth=.5, edgecolor="w") + >>> kws = dict(s=50, linewidth=.5) >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette="Set1", ... hue_order=["Dinner", "Lunch"]) - >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", **kws) ... .add_legend()) Use a dictionary mapping hue levels to colors: @@ -562,7 +562,7 @@ def __init__( >>> pal = dict(Lunch="seagreen", Dinner="gray") >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal, ... hue_order=["Dinner", "Lunch"]) - >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", **kws) ... .add_legend()) Additionally use a different marker for the hue levels: @@ -573,7 +573,7 @@ def __init__( >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal, ... hue_order=["Dinner", "Lunch"], ... hue_kws=dict(marker=["^", "v"])) - >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", **kws) ... .add_legend()) "Wrap" a column variable with many levels into the rows: @@ -625,7 +625,8 @@ def __init__( :context: close-figs >>> g = sns.FacetGrid(tips, col="smoker", row="sex") - >>> g = (g.map(plt.scatter, "total_bill", "tip", color="g", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", + ... color="g", **kws) ... .set_axis_labels("Total bill (US Dollars)", "Tip")) Set other attributes that are shared across the facetes: @@ -634,7 +635,8 @@ def __init__( :context: close-figs >>> g = sns.FacetGrid(tips, col="smoker", row="sex") - >>> g = (g.map(plt.scatter, "total_bill", "tip", color="r", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", + ... color="r", **kws) ... .set(xlim=(0, 60), ylim=(0, 12), ... xticks=[10, 30, 50], yticks=[2, 6, 10])) @@ -654,7 +656,8 @@ def __init__( >>> g = sns.FacetGrid(tips, col="smoker", row="sex", ... margin_titles=True) - >>> g = (g.map(plt.scatter, "total_bill", "tip", color="m", **kws) + >>> g = (g.map(sns.scatterplot, "total_bill", "tip", + ... color="m", **kws) ... .set(xlim=(0, 60), ylim=(0, 12), ... xticks=[10, 30, 50], yticks=[2, 6, 10]) ... .fig.subplots_adjust(wspace=.05, hspace=.05)) @@ -1201,7 +1204,7 @@ def __init__( >>> import seaborn as sns; sns.set() >>> iris = sns.load_dataset("iris") >>> g = sns.PairGrid(iris) - >>> g = g.map(plt.scatter) + >>> g = g.map(sns.scatterplot) Show a univariate distribution on the diagonal: @@ -1210,7 +1213,7 @@ def __init__( >>> g = sns.PairGrid(iris) >>> g = g.map_diag(plt.hist) - >>> g = g.map_offdiag(plt.scatter) + >>> g = g.map_offdiag(sns.scatterplot) (It's not actually necessary to catch the return value every time, as it is the same object, but it makes it easier to deal with the @@ -1223,7 +1226,7 @@ def __init__( >>> g = sns.PairGrid(iris, hue="species") >>> g = g.map_diag(plt.hist) - >>> g = g.map_offdiag(plt.scatter) + >>> g = g.map_offdiag(sns.scatterplot) >>> g = g.add_legend() Use a different style to show multiple histograms: @@ -1233,7 +1236,7 @@ def __init__( >>> g = sns.PairGrid(iris, hue="species") >>> g = g.map_diag(plt.hist, histtype="step", linewidth=3) - >>> g = g.map_offdiag(plt.scatter) + >>> g = g.map_offdiag(sns.scatterplot) >>> g = g.add_legend() Plot a subset of variables @@ -1242,7 +1245,7 @@ def __init__( :context: close-figs >>> g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"]) - >>> g = g.map(plt.scatter) + >>> g = g.map(sns.scatterplot) Pass additional keyword arguments to the functions @@ -1251,7 +1254,7 @@ def __init__( >>> g = sns.PairGrid(iris) >>> g = g.map_diag(plt.hist, edgecolor="w") - >>> g = g.map_offdiag(plt.scatter, edgecolor="w", s=40) + >>> g = g.map_offdiag(sns.scatterplot) Use different variables for the rows and columns: @@ -1261,7 +1264,7 @@ def __init__( >>> g = sns.PairGrid(iris, ... x_vars=["sepal_length", "sepal_width"], ... y_vars=["petal_length", "petal_width"]) - >>> g = g.map(plt.scatter) + >>> g = g.map(sns.scatterplot) Use different functions on the upper and lower triangles: @@ -1280,7 +1283,7 @@ def __init__( >>> g = sns.PairGrid(iris, hue="species", palette="Set2", ... hue_kws={"marker": ["o", "s", "D"]}) - >>> g = g.map(sns.scatterplot, linewidths=1, edgecolor="w", s=40) + >>> g = g.map(sns.scatterplot) >>> g = g.add_legend() """ @@ -2301,8 +2304,7 @@ def jointplot( >>> g = sns.jointplot("petal_length", "sepal_length", data=iris, ... marginal_kws=dict(bins=15, rug=True), - ... annot_kws=dict(stat="r"), - ... s=40, edgecolor="w", linewidth=1) + ... marker="+") """ # Handle deprecations @@ -2336,8 +2338,10 @@ def jointplot( # Plot the data using the grid if kind == "scatter": + from .relational import scatterplot # Avoid circular import + joint_kws.setdefault("color", color) - grid.plot_joint(plt.scatter, **joint_kws) + grid.plot_joint(scatterplot, **joint_kws) marginal_kws.setdefault("kde", False) marginal_kws.setdefault("color", color)