{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import excolor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show Colormap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# List qualitative colormaps\n", "excolor.list_qualitative_cmaps()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# Show \"rtd\" colormap\n", "excolor.show_cmap(\"rtd\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show Colors" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Get colors from colormap\n", "colors = excolor.get_colors(\"rtd\", n=24)\n", "\n", "# Show colors\n", "excolor.show_colors(colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate palette from a seed color\n", "\n", "Mode \"superellipse\" defines the path from black to white. Higher degree produces more vibrant colors." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Seed color\n", "color = '#70B3E0'\n", "\n", "# Generate palette\n", "colors = excolor.generate_palette(color, mode='superellipse', power=3)\n", "\n", "# Show colors\n", "excolor.show_colors(colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate primary colors palette from the same color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Seed color\n", "color = '#70B3E0'\n", "\n", "# Generate a palette for primary CSS colors\n", "primary_colors = excolor.generate_primary_palette(color)\n", "\n", "# Show primary colors\n", "excolor.show_colors(primary_colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate background colors palette from the same color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Seed color\n", "color = '#70B3E0'\n", "\n", "# Generate a palette for background CSS colors\n", "background_colors = excolor.generate_background_palette(color)\n", "\n", "# Show background colors\n", "excolor.show_colors(background_colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate foreground colors palette from the same color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Seed color\n", "color = '#70B3E0'\n", "\n", "# Generate a palette for foreground CSS colors\n", "foreground_colors = excolor.generate_foreground_palette(color)\n", "\n", "# Show foreground colors\n", "excolor.show_colors(foreground_colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set colorcycler for a plot\n", "\n", "By default sets cycler for the current matplotlib ax. To set for current python session use parameter: `globally=True`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Generate sample data\n", "x = np.arange(7)\n", "y1 = [1, 4, 9, 5, 2, 1, 1]\n", "y2 = [2, 3, 4, 3, 4, 5, 3]\n", "y3 = [4, 5, 5, 7, 9, 8, 6]\n", "\n", "# List of data and labels\n", "labels = ['Series A', 'Series B', 'Series C']\n", "data = [y1, y2, y3]\n", "\n", "# Show data\n", "plt.figure(figsize=(10, 6))\n", "\n", "# SET COLOR CYCLER HERE\n", "excolor.set_color_cycler(\"rtd\")\n", "\n", "# Plot data\n", "for i, y in enumerate(data):\n", " plt.plot(x, y, label=labels[i], linewidth=3)\n", " plt.scatter(x, y, s = 100)\n", "\n", "# Add labels and legend\n", "plt.title(\"Combined Line, Scatter, and Fill Plot\")\n", "plt.xlabel(\"X Axis\")\n", "plt.ylabel(\"Y Axis\")\n", "plt.grid(True, linestyle='--', alpha=0.3)\n", "plt.legend()\n", "plt.tight_layout()\n", "plt.show()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Log-scaled colormap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import and generate perlin noise array\n", "from pythonperlin import perlin\n", "\n", "dens = 32\n", "shape = (8,8)\n", "x = perlin(shape, dens=dens)\n", "\n", "# Log-scaled colormap\n", "log_cmap = excolor.logscale_cmap(\"rtd\")\n", "\n", "# Apply log-scaled colormap\n", "plt.figure(figsize=(6,6), facecolor=\"#00000000\")\n", "plt.imshow(np.abs(x), cmap=log_cmap)\n", "plt.axis(\"off\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.12.11" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 1 }