diff --git a/doc/source/user_guide/style.ipynb b/doc/source/user_guide/style.ipynb index 765b2929d3014..86696cc909764 100644 --- a/doc/source/user_guide/style.ipynb +++ b/doc/source/user_guide/style.ipynb @@ -1006,7 +1006,30 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We expect certain styling functions to be common enough that we've included a few \"built-in\" to the `Styler`, so you don't have to write them yourself." + "Some styling functions are common enough that we've \"built them in\" to the `Styler`, so you don't have to write them and apply them yourself. The current list of such functions is:\n", + "\n", + " - [.highlight_null][nullfunc]: for use with identifying missing data. \n", + " - [.highlight_min][minfunc] and [.highlight_max][maxfunc]: for use with identifying extremeties in data.\n", + " - [.highlight_between][betweenfunc] and [.highlight_quantile][quantilefunc]: for use with identifying classes within data.\n", + " - [.background_gradient][bgfunc]: a flexible method for highlighting cells based or their, or other, values on a numeric scale.\n", + " - [.bar][barfunc]: to display mini-charts within cell backgrounds.\n", + " \n", + "The individual documentation on each function often gives more examples of their arguments.\n", + "\n", + "[nullfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_null.rst\n", + "[minfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_min.rst\n", + "[maxfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_max.rst\n", + "[betweenfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_between.rst\n", + "[quantilefunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_quantile.rst\n", + "[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst\n", + "[barfunc]: ../reference/api/pandas.io.formats.style.Styler.bar.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Null" ] }, { @@ -1017,14 +1040,14 @@ "source": [ "df2.iloc[0,2] = np.nan\n", "df2.iloc[4,3] = np.nan\n", - "df2.loc[:4].style.highlight_null(null_color='red')" + "df2.loc[:4].style.highlight_null(null_color='yellow')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "You can create \"heatmaps\" with the `background_gradient` method. These require matplotlib, and we'll use [Seaborn](https://stanford.edu/~mwaskom/software/seaborn/) to get a nice colormap." + "### Highlight Min or Max" ] }, { @@ -1033,17 +1056,15 @@ "metadata": {}, "outputs": [], "source": [ - "import seaborn as sns\n", - "cm = sns.light_palette(\"green\", as_cmap=True)\n", - "\n", - "df2.style.background_gradient(cmap=cm)" + "df2.loc[:4].style.highlight_max(axis=1, props='color:white; font-weight:bold; background-color:darkblue;')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "`Styler.background_gradient` takes the keyword arguments `low` and `high`. Roughly speaking these extend the range of your data by `low` and `high` percent so that when we convert the colors, the colormap's entire range isn't used. This is useful so that you can actually read the text still." + "### Highlight Between\n", + "This method accepts ranges as float, or NumPy arrays or Series provided the indexes match." ] }, { @@ -1052,8 +1073,16 @@ "metadata": {}, "outputs": [], "source": [ - "# Uses the full color range\n", - "df2.loc[:4].style.background_gradient(cmap='viridis')" + "left = pd.Series([1.0, 0.0, 1.0], index=[\"A\", \"B\", \"D\"])\n", + "df2.loc[:4].style.highlight_between(left=left, right=1.5, axis=1, props='color:white; background-color:purple;')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Quantile\n", + "Useful for detecting the highest or lowest percentile values" ] }, { @@ -1062,17 +1091,21 @@ "metadata": {}, "outputs": [], "source": [ - "# Compress the color range\n", - "df2.loc[:4].style\\\n", - " .background_gradient(cmap='viridis', low=.5, high=0)\\\n", - " .highlight_null('red')" + "df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color='yellow')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Background Gradient" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "There's also `.highlight_min` and `.highlight_max`, which is almost identical to the user defined version we created above, and also a `.highlight_null` method. " + "You can create \"heatmaps\" with the `background_gradient` method. These require matplotlib, and we'll use [Seaborn](https://stanford.edu/~mwaskom/software/seaborn/) to get a nice colormap." ] }, { @@ -1081,7 +1114,19 @@ "metadata": {}, "outputs": [], "source": [ - "df2.loc[:4].style.highlight_max(axis=0)" + "import seaborn as sns\n", + "cm = sns.light_palette(\"green\", as_cmap=True)\n", + "\n", + "df2.style.background_gradient(cmap=cm)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[.background_gradient][bgfunc] has a number of keyword arguments to customise the gradients and colors. See its documentation.\n", + "\n", + "[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst" ] }, {