Skip to content

Commit

Permalink
Add set_theme() to replace set() (#2253)
Browse files Browse the repository at this point in the history
* Add set_theme function and change set to an alias

* Add test

* Change set -> set_theme everywhere

* Update aesthetics tutorial

* Update API page and release notes

* Expose set_theme as public API

(cherry picked from commit 0b7697d)
  • Loading branch information
mwaskom committed Sep 8, 2020
1 parent f83941c commit afba270
Show file tree
Hide file tree
Showing 81 changed files with 161 additions and 123 deletions.
7 changes: 4 additions & 3 deletions doc/api.rst
Expand Up @@ -116,20 +116,21 @@ Joint grids

.. _style_api:

Style control
-------------
Themes
------

.. autosummary::
:toctree: generated/

set
set_theme
axes_style
set_style
plotting_context
set_context
set_color_codes
reset_defaults
reset_orig
set

.. _palette_api:

Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/FacetGrid.ipynb
Expand Up @@ -11,7 +11,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set(style=\"ticks\")"
"sns.set_theme(style=\"ticks\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/JointGrid.ipynb
Expand Up @@ -11,7 +11,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/PairGrid.ipynb
Expand Up @@ -10,7 +10,7 @@
},
"outputs": [],
"source": [
"import seaborn as sns; sns.set()\n",
"import seaborn as sns; sns.set_theme()\n",
"import matplotlib.pyplot as plt"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/color_palette.ipynb
Expand Up @@ -10,7 +10,7 @@
},
"outputs": [],
"source": [
"import seaborn as sns; sns.set()"
"import seaborn as sns; sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/displot.ipynb
Expand Up @@ -10,7 +10,7 @@
},
"outputs": [],
"source": [
"import seaborn as sns; sns.set(style=\"ticks\")"
"import seaborn as sns; sns.set_theme(style=\"ticks\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/ecdfplot.ipynb
Expand Up @@ -17,7 +17,7 @@
},
"outputs": [],
"source": [
"import seaborn as sns; sns.set()"
"import seaborn as sns; sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/histplot.ipynb
Expand Up @@ -11,7 +11,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set(style=\"white\")"
"sns.set_theme(style=\"white\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/jointplot.ipynb
Expand Up @@ -11,7 +11,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set(style=\"white\")"
"sns.set_theme(style=\"white\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/kdeplot.ipynb
Expand Up @@ -10,7 +10,7 @@
},
"outputs": [],
"source": [
"import seaborn as sns; sns.set()"
"import seaborn as sns; sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/lineplot.ipynb
Expand Up @@ -15,7 +15,7 @@
"import seaborn as sns\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/pairplot.ipynb
Expand Up @@ -11,7 +11,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set(style=\"ticks\")"
"sns.set_theme(style=\"ticks\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/relplot.ipynb
Expand Up @@ -19,7 +19,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set(style=\"ticks\")"
"sns.set_theme(style=\"ticks\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/rugplot.ipynb
Expand Up @@ -13,7 +13,7 @@
"metadata": {},
"outputs": [],
"source": [
"import seaborn as sns; sns.set()\n",
"import seaborn as sns; sns.set_theme()\n",
"tips = sns.load_dataset(\"tips\")\n",
"sns.kdeplot(data=tips, x=\"total_bill\")\n",
"sns.rugplot(data=tips, x=\"total_bill\")"
Expand Down
2 changes: 1 addition & 1 deletion doc/docstrings/scatterplot.ipynb
Expand Up @@ -14,7 +14,7 @@
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions doc/introduction.ipynb
Expand Up @@ -35,7 +35,7 @@
"import seaborn as sns\n",
"\n",
"# Apply the default theme\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"# Load an example dataset\n",
"tips = sns.load_dataset(\"tips\")\n",
Expand Down Expand Up @@ -89,7 +89,7 @@
"outputs": [],
"source": [
"# Apply the default theme\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down Expand Up @@ -409,7 +409,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.set(style=\"ticks\", font_scale=1.25)\n",
"sns.set_theme(style=\"ticks\", font_scale=1.25)\n",
"g = sns.relplot(\n",
" data=penguins,\n",
" x=\"bill_length_mm\", y=\"bill_depth_mm\", hue=\"body_mass_g\",\n",
Expand Down
5 changes: 5 additions & 0 deletions doc/releases/v0.11.0.txt
Expand Up @@ -110,6 +110,11 @@ Documentation improvements

- |Docs| Improved cross-linking within the seaborn docs and between the seaborn and matplotlib docs.

Theming
~~~~~~~

- |API| The :func:`set` function has been renamed to :func:`set_theme` for more clarity about what it does. For the foreseeable future, :func:`set` will remain as an alias, but it is recommended to update your code.

Relational plots
^^^^^^^^^^^^^^^^

Expand Down
12 changes: 6 additions & 6 deletions doc/tutorial/aesthetics.ipynb
Expand Up @@ -94,7 +94,7 @@
"cell_type": "raw",
"metadata": {},
"source": [
"To switch to seaborn defaults, simply call the :func:`set` function."
"To switch to seaborn defaults, simply call the :func:`set_theme` function."
]
},
{
Expand All @@ -103,15 +103,15 @@
"metadata": {},
"outputs": [],
"source": [
"sns.set()\n",
"sns.set_theme()\n",
"sinplot()"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"(Note that in versions of seaborn prior to 0.8, :func:`set` was called on import. On later versions, it must be explicitly invoked).\n",
"(Note that in versions of seaborn prior to 0.8, :func:`set_theme` was called on import. On later versions, it must be explicitly invoked).\n",
"\n",
"Seaborn splits matplotlib parameters into two independent groups. The first group sets the aesthetic style of the plot, and the second scales various elements of the figure so that it can be easily incorporated into different contexts.\n",
"\n",
Expand Down Expand Up @@ -283,7 +283,7 @@
"Overriding elements of the seaborn styles\n",
"-----------------------------------------\n",
"\n",
"If you want to customize the seaborn styles, you can pass a dictionary of parameters to the ``rc`` argument of :func:`axes_style` and :func:`set_style`. Note that you can only override the parameters that are part of the style definition through this method. (However, the higher-level :func:`set` function takes a dictionary of any matplotlib parameters).\n",
"If you want to customize the seaborn styles, you can pass a dictionary of parameters to the ``rc`` argument of :func:`axes_style` and :func:`set_style`. Note that you can only override the parameters that are part of the style definition through this method. (However, the higher-level :func:`set_theme` function takes a dictionary of any matplotlib parameters).\n",
"\n",
"If you want to see what parameters are included, you can just call the function with no arguments, which will return the current settings:"
]
Expand Down Expand Up @@ -325,7 +325,7 @@
"\n",
"A separate set of parameters control the scale of plot elements, which should let you use the same code to make plots that are suited for use in settings where larger or smaller plots are appropriate.\n",
"\n",
"First let's reset the default parameters by calling :func:`set`:"
"First let's reset the default parameters by calling :func:`set_theme`:"
]
},
{
Expand All @@ -334,7 +334,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/axis_grids.ipynb
Expand Up @@ -54,7 +54,7 @@
},
"outputs": [],
"source": [
"sns.set(style=\"ticks\")"
"sns.set_theme(style=\"ticks\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/categorical.ipynb
Expand Up @@ -56,7 +56,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set(style=\"ticks\", color_codes=True)"
"sns.set_theme(style=\"ticks\", color_codes=True)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/color_palettes.ipynb
Expand Up @@ -38,7 +38,7 @@
"import numpy as np\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set(style=\"white\", rc={\"xtick.major.pad\": 1, \"ytick.major.pad\": 1})"
"sns.set_theme(style=\"white\", rc={\"xtick.major.pad\": 1, \"ytick.major.pad\": 1})"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/data_structure.ipynb
Expand Up @@ -39,7 +39,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/distributions.ipynb
Expand Up @@ -38,7 +38,7 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import seaborn as sns; sns.set()"
"import seaborn as sns; sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/function_overview.ipynb
Expand Up @@ -38,7 +38,7 @@
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"from IPython.display import HTML\n",
"sns.set()"
"sns.set_theme()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/regression.ipynb
Expand Up @@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.set(color_codes=True)"
"sns.set_theme(color_codes=True)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/relational.ipynb
Expand Up @@ -40,7 +40,7 @@
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"sns.set(style=\"darkgrid\")"
"sns.set_theme(style=\"darkgrid\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/anscombes_quartet.py
Expand Up @@ -5,7 +5,7 @@
_thumb: .4, .4
"""
import seaborn as sns
sns.set(style="ticks")
sns.set_theme(style="ticks")

# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
Expand Down
2 changes: 1 addition & 1 deletion examples/different_scatter_variables.py
Expand Up @@ -7,7 +7,7 @@
"""
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
sns.set_theme(style="whitegrid")

# Load the example diamonds dataset
diamonds = sns.load_dataset("diamonds")
Expand Down
2 changes: 1 addition & 1 deletion examples/errorband_lineplots.py
Expand Up @@ -6,7 +6,7 @@
"""
import seaborn as sns
sns.set(style="darkgrid")
sns.set_theme(style="darkgrid")

# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
Expand Down
2 changes: 1 addition & 1 deletion examples/faceted_histogram.py
Expand Up @@ -6,7 +6,7 @@
"""
import seaborn as sns

sns.set(style="darkgrid")
sns.set_theme(style="darkgrid")
df = sns.load_dataset("penguins")
sns.displot(
df, x="flipper_length_mm", col="species", row="sex",
Expand Down
2 changes: 1 addition & 1 deletion examples/faceted_lineplot.py
Expand Up @@ -6,7 +6,7 @@
"""
import seaborn as sns
sns.set(style="ticks")
sns.set_theme(style="ticks")

dots = sns.load_dataset("dots")

Expand Down
2 changes: 1 addition & 1 deletion examples/grouped_barplot.py
Expand Up @@ -5,7 +5,7 @@
_thumb: .36, .5
"""
import seaborn as sns
sns.set(style="whitegrid")
sns.set_theme(style="whitegrid")

penguins = sns.load_dataset("penguins")

Expand Down
2 changes: 1 addition & 1 deletion examples/grouped_boxplot.py
Expand Up @@ -6,7 +6,7 @@
"""
import seaborn as sns
sns.set(style="ticks", palette="pastel")
sns.set_theme(style="ticks", palette="pastel")

# Load the example tips dataset
tips = sns.load_dataset("tips")
Expand Down
2 changes: 1 addition & 1 deletion examples/grouped_violinplots.py
Expand Up @@ -5,7 +5,7 @@
_thumb: .44, .47
"""
import seaborn as sns
sns.set(style="whitegrid")
sns.set_theme(style="whitegrid")

# Load the example tips dataset
tips = sns.load_dataset("tips")
Expand Down
2 changes: 1 addition & 1 deletion examples/heat_scatter.py
Expand Up @@ -6,7 +6,7 @@
"""
import seaborn as sns
sns.set(style="whitegrid")
sns.set_theme(style="whitegrid")

# Load the brain networks dataset, select subset, and collapse the multi-index
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
Expand Down

0 comments on commit afba270

Please sign in to comment.