{ "cells": [ { "cell_type": "markdown", "id": "4826e8c1", "metadata": {}, "source": [ "# chromo-map Jupyter Integration Demo\n", "\n", "This notebook demonstrates chromo-map's rich visual integration with Jupyter notebooks. You'll see how colors, gradients, and swatches automatically display with beautiful visual representations, making color exploration and manipulation highly interactive.\n", "\n", "## Key Features Demonstrated:\n", "- **Rich Color Display**: Colors show as colored squares with hover information\n", "- **Gradient Visualization**: Smooth color transitions displayed as horizontal bars\n", "- **Swatch Organization**: Multiple gradients arranged in organized grids\n", "- **Interactive Exploration**: Real-time visual feedback for color manipulations\n", "- **Professional Palettes**: Visual access to Plotly, matplotlib, and Palettable color schemes" ] }, { "cell_type": "markdown", "id": "4b933397", "metadata": {}, "source": [ "## 1. Import Required Libraries\n", "\n", "First, let's import chromo-map and any additional libraries needed for this demonstration." ] }, { "cell_type": "code", "execution_count": null, "id": "da97e7c3", "metadata": {}, "outputs": [], "source": [ "# Import chromo-map classes\n", "from chromo_map import Color, Gradient, Swatch, cmaps\n", "import numpy as np\n", "\n", "# For this demo, we'll focus on chromo-map's built-in Jupyter visualization\n", "# No additional plotting libraries needed - chromo-map handles the display!\n", "\n", "print(\"āœ… chromo-map imported successfully!\")\n", "print(f\"šŸ“Š Total available gradients: {len(cmaps.all)}\")\n", "print(f\"šŸŽØ Plotly gradients: {sum(len(cat) for cat in cmaps.plotly_by_type.values())}\")\n", "print(f\"šŸ”¬ Matplotlib gradients: {sum(len(cat) for cat in cmaps.matplotlib_by_type.values())}\")\n", "print(f\"šŸŽ­ Palettable gradients: {sum(len(cat) for cat in cmaps.palettable_by_type.values())}\")" ] }, { "cell_type": "markdown", "id": "929b73d8", "metadata": {}, "source": [ "## 2. Basic Color Display in Jupyter\n", "\n", "In Jupyter notebooks, chromo-map Color objects automatically display as beautiful colored squares with detailed information. Just create a color and put it as the last line of a cell!" ] }, { "cell_type": "code", "execution_count": null, "id": "3316239f", "metadata": {}, "outputs": [], "source": [ "# Create a vibrant orange color\n", "vibrant_orange = Color('#ff6b35')\n", "vibrant_orange # This will display as a colored square with hover info!" ] }, { "cell_type": "code", "execution_count": null, "id": "016ed1d5", "metadata": {}, "outputs": [], "source": [ "# Let's create several colors using different input methods\n", "colors = [\n", " Color('#3498db'), # Hex string (blue)\n", " Color('forestgreen'), # Named color\n", " Color('rgb(255, 107, 53)'), # RGB tuple (orange)\n", " Color((0.8, 0.2, 0.9, 0.7)) # RGBA with transparency (purple)\n", "]\n", "\n", "# Display all colors - each will show as a colored square\n", "print(\"šŸŽØ Multiple color display:\")\n", "for i, color in enumerate(colors):\n", " print(f\"Color {i+1}:\")\n", " display(color) # Explicitly display each color" ] }, { "cell_type": "markdown", "id": "09664faf", "metadata": {}, "source": [ "## 3. Gradient Visualization\n", "\n", "Gradients display as smooth horizontal color bars, showing the beautiful transitions between colors. This makes it easy to see how colors blend and flow." ] }, { "cell_type": "code", "execution_count": null, "id": "e6f75e2b", "metadata": {}, "outputs": [], "source": [ "# Create a simple two-color gradient\n", "sunset_gradient = Gradient(['#ff6b35', '#f7931e'], 'Sunset')\n", "sunset_gradient # Displays as a horizontal color bar!" ] }, { "cell_type": "code", "execution_count": null, "id": "e938052b", "metadata": {}, "outputs": [], "source": [ "# Create a rainbow gradient with multiple colors\n", "rainbow = Gradient(['red', 'orange', 'yellow', 'green', 'blue', 'purple'], 'Rainbow')\n", "print(\"🌈 Rainbow Gradient:\")\n", "rainbow" ] }, { "cell_type": "code", "execution_count": null, "id": "ff90f779", "metadata": {}, "outputs": [], "source": [ "# Access a professional gradient from the catalog\n", "plotly_viridis = cmaps.plotly_by_type['sequential']['Viridis']\n", "print(\"šŸ”¬ Plotly Viridis (scientific colormap):\")\n", "plotly_viridis" ] }, { "cell_type": "markdown", "id": "68f2b4ab", "metadata": {}, "source": [ "## 4. Swatch Grid Display\n", "\n", "Swatches organize multiple gradients into beautiful grids, perfect for comparing different color schemes or organizing palettes by theme." ] }, { "cell_type": "code", "execution_count": null, "id": "d24f7771", "metadata": {}, "outputs": [], "source": [ "# Create a swatch with different gradient themes\n", "nature_gradients = [\n", " Gradient(['#2d5a27', '#8bc34a'], 15), # Forest green\n", " Gradient(['#1565c0', '#42a5f5'], 15), # Ocean blue\n", " Gradient(['#f57c00', '#ffcc02'], 15), # Sunset orange\n", " Gradient(['#6a1b9a', '#ba68c8'], 15), # Lavender purple\n", "]\n", "\n", "nature_swatch = Swatch(nature_gradients)\n", "print(\"🌿 Nature-Inspired Color Swatch:\")\n", "nature_swatch" ] }, { "cell_type": "markdown", "id": "d1c1c435", "metadata": {}, "source": [ "## 5. Interactive Color Exploration\n", "\n", "One of the most powerful features is being able to manipulate colors and see the results immediately. Let's explore color transformations with instant visual feedback!" ] }, { "cell_type": "code", "execution_count": null, "id": "b1f64b81", "metadata": {}, "outputs": [], "source": [ "# Start with a base color\n", "base_color = Color('#e74c3c') # Red\n", "print(\"šŸ”“ Original Color:\")\n", "display(base_color)\n", "\n", "# Create variations using different adjustments\n", "print(\"\\nšŸŽØ Color Transformations:\")\n", "print(\"Brighter (+30%):\")\n", "display(base_color.adjust_brightness(0.3))\n", "\n", "print(\"Darker (-30%):\")\n", "display(base_color.adjust_brightness(-0.3))\n", "\n", "print(\"More Saturated (+40%):\")\n", "display(base_color.adjust_saturation(0.4))\n", "\n", "print(\"Less Saturated (-50%):\")\n", "display(base_color.adjust_saturation(-0.5))\n", "\n", "print(\"Hue Shifted (+60°):\")\n", "display(base_color.adjust_hue(60))" ] }, { "cell_type": "code", "execution_count": null, "id": "b3969afb", "metadata": {}, "outputs": [], "source": [ "# Explore color relationships\n", "base = Color('#3498db') # Blue\n", "print(\"šŸ”µ Base Color:\")\n", "display(base)\n", "\n", "print(\"\\nšŸŽ­ Color Relationships:\")\n", "print(\"Complementary (opposite on color wheel):\")\n", "display(base.complementary())\n", "\n", "print(\"Analogous colors (neighboring on color wheel):\")\n", "analogous_colors = base.analogous(angle=3)\n", "for i, color in enumerate(analogous_colors):\n", " print(f\"Analogous {i+1}:\")\n", " display(color)" ] }, { "cell_type": "markdown", "id": "e81bea58", "metadata": {}, "source": [ "## 6. Working with Color Palettes\n", "\n", "chromo-map provides access to hundreds of professional color palettes from Plotly, matplotlib, and Palettable. Let's explore some of the most popular ones." ] }, { "cell_type": "code", "execution_count": null, "id": "97ba8470", "metadata": {}, "outputs": [], "source": [ "# Showcase Plotly qualitative palettes\n", "print(\"šŸŽØ Plotly Qualitative Palettes:\")\n", "\n", "plotly_qualitative = cmaps.plotly_by_type['qualitative']\n", "showcase_palettes = ['Plotly', 'D3', 'G10', 'T10']\n", "\n", "for palette_name in showcase_palettes:\n", " if palette_name in plotly_qualitative:\n", " print(f\"\\n{palette_name} ({len(plotly_qualitative[palette_name])} colors):\")\n", " display(plotly_qualitative[palette_name])" ] }, { "cell_type": "code", "execution_count": null, "id": "48b35698", "metadata": {}, "outputs": [], "source": [ "# Show some beautiful sequential palettes\n", "print(\"šŸ”¬ Scientific Sequential Palettes:\")\n", "\n", "sequential_palettes = ['Viridis', 'Plasma', 'Inferno', 'Magma']\n", "for palette_name in sequential_palettes:\n", " if palette_name in cmaps.plotly_by_type['sequential']:\n", " print(f\"\\n{palette_name}:\")\n", " display(cmaps.plotly_by_type['sequential'][palette_name])" ] }, { "cell_type": "markdown", "id": "f64cb105", "metadata": {}, "source": [ "## 7. Visual Color Comparisons\n", "\n", "Let's create side-by-side comparisons to see the effects of different color manipulations. This is perfect for understanding how adjustments affect the overall appearance." ] }, { "cell_type": "code", "execution_count": null, "id": "252126f5", "metadata": {}, "outputs": [], "source": [ "# Take a Plotly gradient and create variations\n", "original_gradient = cmaps.plotly_by_type['qualitative']['Plotly']\n", "\n", "# Create different manipulations\n", "variations = [\n", " (\"Original\", original_gradient),\n", " (\"Brightened (+25%)\", original_gradient.adjust_brightness(0.25)),\n", " (\"Darkened (-25%)\", original_gradient.adjust_brightness(-0.25)),\n", " (\"More Saturated (+30%)\", original_gradient.adjust_saturation(0.3)),\n", " (\"Less Saturated (-40%)\", original_gradient.adjust_saturation(-0.4)),\n", "]\n", "\n", "print(\"šŸŽØ Gradient Manipulation Comparison:\")\n", "for name, gradient in variations:\n", " print(f\"\\n{name}:\")\n", " display(gradient)" ] }, { "cell_type": "code", "execution_count": null, "id": "f0e2d878", "metadata": {}, "outputs": [], "source": [ "# Create a swatch to organize the variations nicely\n", "comparison_gradients = [var[1] for var in variations]\n", "comparison_swatch = Swatch(comparison_gradients)\n", "\n", "print(\"šŸ“Š Organized Comparison Swatch:\")\n", "comparison_swatch" ] }, { "cell_type": "markdown", "id": "c650fa00", "metadata": {}, "source": [ "## šŸŽ‰ Conclusion\n", "\n", "This notebook demonstrated chromo-map's powerful capabilities:\n", "\n", "### šŸŽØ **Rich Jupyter Integration**:\n", "- **Visual Display**: Colors and gradients automatically show beautiful visual representations\n", "- **Interactive Exploration**: Immediate visual feedback for color manipulations\n", "- **Organized Presentation**: Swatches for comparing multiple palettes\n", "- **Professional Palettes**: Easy access to hundreds of curated color schemes\n", "\n", "### šŸ”„ **matplotlib Compatibility - The Key Advantage**:\n", "- **Drop-in Replacement**: Use any chromo-map gradient as a matplotlib colormap\n", "- **Professional Colors**: Access Plotly and Palettable palettes in matplotlib plots\n", "- **Enhanced Manipulation**: Modify colors while maintaining matplotlib compatibility\n", "- **Best of Both Worlds**: Professional color schemes + enhanced functionality\n", "\n", "### ⚔ **Perfect for Data Science**:\n", "- Real-time color experimentation in Jupyter\n", "- Professional visualizations with superior color palettes\n", "- Seamless integration with existing matplotlib workflows\n", "- Enhanced accessibility and color theory features\n", "\n", "## Next Steps\n", "\n", "Try experimenting with:\n", "- Different color manipulation parameters (`adjust_brightness`, `adjust_hue`, etc.)\n", "- Combining colors from different sources (Plotly + Palettable + matplotlib)\n", "- Creating custom gradients for your specific projects\n", "- Using accessibility features to ensure WCAG compliance\n", "- Exploring color theory relationships for better design\n", "\n", "**The power of chromo-map**: Professional color palettes + enhanced manipulation + matplotlib compatibility = Perfect for data visualization! šŸŽØāœØ" ] }, { "cell_type": "markdown", "id": "e7f3e501", "metadata": {}, "source": [ "## 8. Matplotlib Compatibility\n", "\n", "**The Key Advantage**: chromo-map gradients are fully compatible with matplotlib! This means you can use professional color palettes from Plotly and Palettable in your matplotlib plots while gaining enhanced color manipulation features." ] }, { "cell_type": "code", "execution_count": null, "id": "987aa8d8", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Get the Plotly qualitative palette (10 colors) - not available in matplotlib!\n", "plotly_colors = cmaps.plotly_by_type['qualitative']['Plotly']\n", "\n", "print(f\"šŸŽØ Using Plotly palette with {len(plotly_colors)} colors:\")\n", "plotly_colors" ] }, { "cell_type": "code", "execution_count": null, "id": "7332737a", "metadata": {}, "outputs": [], "source": [ "# Create sample data for area plot\n", "x = np.linspace(0, 10, 100)\n", "data = np.array([np.sin(x + i) + i*0.3 for i in range(len(plotly_colors))])\n", "\n", "# Create area plot using each color from the Plotly palette\n", "fig, ax = plt.subplots(figsize=(12, 8))\n", "for i, series in enumerate(data):\n", " ax.fill_between(x, i*0.2, series + i*0.2, \n", " color=plotly_colors[i].hex, \n", " alpha=0.7, label=f'Series {i+1}')\n", "\n", "ax.set_title('Area Plot Using Plotly Color Palette\\n(Professional colors not available in matplotlib!)', \n", " fontsize=14, fontweight='bold')\n", "ax.set_xlabel('X Values')\n", "ax.set_ylabel('Y Values')\n", "ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left')\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "8cd099f1", "metadata": {}, "outputs": [], "source": [ "# Now demonstrate enhanced color manipulation - create a modified version\n", "lightened_colors = plotly_colors.adjust_saturation(0.75) # Reduce saturation by 25%\n", "\n", "print(\"šŸŽØ Modified palette (reduced saturation):\")\n", "lightened_colors" ] }, { "cell_type": "code", "execution_count": null, "id": "f167fd07", "metadata": {}, "outputs": [], "source": [ "# Create another plot with the modified colors\n", "fig, ax = plt.subplots(figsize=(12, 8))\n", "for i, series in enumerate(data):\n", " ax.fill_between(x, i*0.2, series + i*0.2, \n", " color=lightened_colors[i].hex, \n", " alpha=0.7, label=f'Modified Series {i+1}')\n", "\n", "ax.set_title('Same Plot with Enhanced Color Manipulation\\n(Reduced saturation using chromo-map)', \n", " fontsize=14, fontweight='bold')\n", "ax.set_xlabel('X Values')\n", "ax.set_ylabel('Y Values')\n", "ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left')\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "684bc7de", "metadata": {}, "outputs": [], "source": [ "# Demonstrate using chromo-map gradients as matplotlib colormaps\n", "viridis_plotly = cmaps.plotly_by_type['sequential']['Viridis']\n", "\n", "# Create sample 2D data\n", "x = np.linspace(-3, 3, 100)\n", "y = np.linspace(-3, 3, 100)\n", "X, Y = np.meshgrid(x, y)\n", "Z = np.sin(np.sqrt(X**2 + Y**2))\n", "\n", "# Use chromo-map gradient as matplotlib colormap\n", "fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))\n", "\n", "# Plot with chromo-map Viridis\n", "im1 = ax1.imshow(Z, cmap=viridis_plotly, extent=[-3, 3, -3, 3])\n", "ax1.set_title('Using chromo-map Viridis\\n(Professional Plotly version)')\n", "plt.colorbar(im1, ax=ax1, shrink=0.8)\n", "\n", "# Plot with standard matplotlib viridis for comparison\n", "im2 = ax2.imshow(Z, cmap='viridis', extent=[-3, 3, -3, 3])\n", "ax2.set_title('Standard matplotlib viridis\\n(For comparison)')\n", "plt.colorbar(im2, ax=ax2, shrink=0.8)\n", "\n", "plt.tight_layout()\n", "plt.show()\n", "\n", "print(\"šŸ”¬ Both plots use viridis, but chromo-map gives you access to the professional Plotly version!\")" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }