Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer scatterplot over plt.scatter in examples and plotters #2069

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ 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:

.. plot::
: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:
Expand All @@ -575,10 +575,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:
Expand All @@ -589,7 +589,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:
Expand All @@ -600,7 +600,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:
Expand Down Expand Up @@ -652,7 +652,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:
Expand All @@ -661,7 +662,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]))

Expand All @@ -681,7 +683,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))
Expand Down Expand Up @@ -1242,7 +1245,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:

Expand All @@ -1251,7 +1254,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
Expand All @@ -1264,7 +1267,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:
Expand All @@ -1274,7 +1277,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
Expand All @@ -1283,7 +1286,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

Expand All @@ -1292,7 +1295,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:

Expand All @@ -1302,7 +1305,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:

Expand All @@ -1321,7 +1324,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()

"""
Expand Down Expand Up @@ -2362,9 +2365,8 @@ def jointplot(
:context: close-figs

>>> g = sns.jointplot(x="petal_length", y="sepal_length", data=iris,
... marginal_kws=dict(bins=15),
... annot_kws=dict(stat="r"),
... s=40, edgecolor="w", linewidth=1)
... marginal_kws=dict(bins=15, rug=True),
... marker="+")

"""
# Avoid circular import
Expand Down Expand Up @@ -2401,8 +2403,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)
Expand Down