{ "cells": [ { "cell_type": "markdown", "id": "5e3b2762-2738-4a88-95f2-66e8e3be8c51", "metadata": {}, "source": [ "###
San Jose State University
Department of Applied Data Science

**DATA 200
Computational Programming for Data Analytics**

Spring 2024
Instructor: Ron Mak
" ] }, { "cell_type": "markdown", "id": "3868a95d-9681-463c-b8cb-68a99c838ce2", "metadata": {}, "source": [ "# `seaborn` color palettes" ] }, { "cell_type": "markdown", "id": "b398ee20-f907-44ff-8a07-a89bc1d7588e", "metadata": {}, "source": [ "#### The `color_palette()` function is an interface for generating colors.\n", "``` Python\n", "seaborn.color_palette(palette, n_colors, desat)\n", "```\n", "where\n", "- #### ***palette*** (optional): The name of the palette, or `None` to return the current palette.\n", "- #### ***n_colors*** (optional): The number of colors in the palette. If this number is larger than the number of colors in the palette, the colors are cyled.\n", "- #### ***desat*** (optional): The proportion by which to desaturate each color.\n", "#### Call `set_palette()` to set the palette for all plots.\n", "``` Python\n", "seaborn.set_palette(palette, n_colors, desat)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "id": "5d96df41-f2bf-486b-9708-6c6b69b644a1", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": null, "id": "2b5154b4-1fbf-4201-a054-1280c6ed4aa1", "metadata": {}, "outputs": [], "source": [ "for pal in ['deep', 'muted', 'bright', 'pastel', \n", " 'dark', 'colorblind']:\n", " print(f'Palette {pal}')\n", " palette = sns.color_palette(pal)\n", " sns.palplot(palette)\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "12b92e6c-4590-4207-be04-a3bf1d5c3fc7", "metadata": {}, "outputs": [], "source": [ "plt.close()" ] }, { "cell_type": "markdown", "id": "1bb0d214-12de-4df1-b4dd-93dd351679ef", "metadata": {}, "source": [ "#### Adapted from ***Data Visualization with Python***, by Mario Döbler and Tim Großmann, Packt 2019, ISBN 978-1-78995-646-7" ] }, { "cell_type": "code", "execution_count": null, "id": "a114258b-fd23-40f2-b54f-13567404afa2", "metadata": {}, "outputs": [], "source": [ "# Additional material (c) 2024 by Ronald Mak" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 5 }