{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Dario Radečić",
  "title_listed": "How to Convert a Single HEX Color Code into a Monochrome Color Palette with Python",
  "keywords": "Python,颜色,可视化",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/how-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de/",
  "publish_date": "2024-09",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "2efaaf940ede",
  "collected_at": "2026-10-01T20:54:40",
  "title": "How to Convert a Single HEX Color Code into a Monochrome Color Palette with Python | Towards Data Science",
  "body_markdown": "Toggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# How to Convert a Single HEX Color Code into a Monochrome Color Palette with Python\nSpoiler: It's harder than you think.\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nSeptember 27, 20248 min read\n![Article thumbnail \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1din5xskMRGuBgjQ7pejM5A.png)\nArticle thumbnail (image by author)\nColors are hard, especially if you don't have an eye for design.\nMost of us tech professionals don't. The upside is that Python can do most of the heavy lifting for you. It can generate an entire monochromatic color palette that'll look stunning on any stacked chart.\nThe downside is that getting there requires a fair bit of coding. You have to write custom functions to convert a color from HEX to HSL and vice versa, and figure out if the starting color is too bright, as well as how much lighter each next color should be.\n**Adding insult to injury, I haven't found a single fully working Python library capable of accomplishing this task.**\nThat's where this article chimes in.\nIf you're a [subscriber to my Substack](https://darioradecic.substack.com), you can skip the reading and [download the notebook](https://github.com/darioradecic/Data-Doodles-with-Python/tree/main/018_hex_to_monochrome_color_palette) instead.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist), [Computer Science](https://roadmap.sh/computer-science) and [Data Analyst](https://roadmap.sh/data-analyst) roadmaps.\n## HEX, HSL, RGB - What's With All The Jargon?\nLet's quickly cover three color formats you need to know:\n  * **HEX** - A six-digit code typically used in web development and graphic design. The color code starts with a `#`, followed by six hexadecimal digits. Pairs of two represent the amount of red, green, and blue. For example, `#FF5633` - `FF` represents red, `56` represents green, and `33` represents blue. Values can range from `00` to `FF` in hexadecimal, or 0 to 255 in decimal.\n  * **RGB** - A color model that defines colors based on their red, green, and blue components. Each value ranges from 0 to 255. Different amounts of red, green, and blue are combined to produce a wide range of colors. It can be easily translated into HEX - just convert the RGB amounts into their hexadecimal representation.\n  * **HSL** - A cylindrical coordinate representation of colors. It describes colors based on hue, saturation, and lightness. Hue is the color itself represented as an angle on a color wheel (0 to 360 degrees with 0 degrees being red, 120 degrees being green, and 240 degrees being blue). Saturation represents the vividness of the color expressed in percentages (0–100%). And lightness represents how light or dark the color is (0% being black and 100% being white).\n\n\n**The process of creating a monochrome palette boils down to adjusting the Lightness of color in HSL format while keeping Hue and Saturation unchanged.**\nFor a better idea, try any color wheel tool online. Enter a HEX code, and you'll see its other color system versions:\n![Image 1 - Hex color code in different color models \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1ifmH8wu-vEibMMsLZFIbVg.png)\nImage 1 - Hex color code in different color models (image by author)\nBut to get there, you'll have to convert a HEX color to RGB, RGB to HSL, get an array of colors with different lightness percentages, and then convert it back to HEX.\nThe problem is, some color codes can't be converted 100% accurately, and will be **estimated**. That's fine, as you'll end up with a visually indistinguishable color with a slightly different HEX code.\nEnough with the theory - let's start coding!\n## How to Create a Monochrome Color Palette From Scratch\nStart by importing the libraries:\npython\n\n```\nimport numpy as np\nimport pandas as pd\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n```\n\nYou can optionally use my [custom Matplotlib theme](https://open.substack.com/pub/darioradecic/p/heres-my-custom-light-theme-that?r=48ma0u&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true) to make the charts stand out without any manual tweaks:\npython\n\n```\nmpl.style.use(\"custom_light.mplstyle\")\n```\n\nOnto the code now.\nThe `MonochromePaletteGenerator` class implements the following methods:\n  * `__init__()` - A class constructor that initializes two attributes: `MIN_ALLOWED_LIGHTNESS` (integer set to 15 to ensure the palette does not start with too light a color) and `max_palette_lightness` (integer set to 95, it limits the lightness of the lightest color in the palette).\n  * `__validate_starting_lightness()` - Checks if the starting lightness value matches the range set in the constructor.\n  * `hex_to_hxl()` - Given a HEX color code it first converts it into RGB and then calculates lightness, saturation, and hue through a somewhat involved process.\n  * `hsl_to_hex()` - Given the values for hue, saturation, and lightness, the method estimates RGB values through primes and then converts them back to a HEX color code.\n  * `__create_lightness_range()` - A helper method that creates `n_colors` with linearly spaced lightness values for a monochrome color palette. You'll want to tweak this method to adjust the spacing between the colors (e.g., don't use linear spacing).\n  * `create_hex_code_palette()` - Given a starting HEX color code and a number of colors, it translates HEX to HSL, creates a lightness range, and converts a list of HSL colors into HEX format.\n  * `create_matplotlib_palette()` - Uses Matplotlib's `mpl.colors.ListedColormap` to create a color palette you can use in Matplotlib.\n\n\nHere's what it boils down to in the code:\npython\n\n```\nclass MonochromePaletteGenerator:\n    def __init__(self, max_palette_lightness: int = 95):\n        self.MIN_ALLOWED_LIGHTNESS = 15\n        self.max_palette_lightness = max_palette_lightness\n\n    def __validate_starting_lightness(self, starting_lightness: int) -> bool:\n        if starting_lightness <= self.MIN_ALLOWED_LIGHTNESS:\n            return True\n        return False\n\n    @staticmethod\n    def hex_to_hsl(hex_color: str) -> tuple:\n        # Remove the \"#\" character if present\n        hex_color = hex_color.lstrip('#')\n\n        # Convert hex to RGB\n        r = int(hex_color[0:2], 16) / 255.0\n        g = int(hex_color[2:4], 16) / 255.0\n        b = int(hex_color[4:6], 16) / 255.0\n\n        # Find the maximum and minimum RGB values\n        max_val = max(r, g, b)\n        min_val = min(r, g, b)\n        delta = max_val - min_val\n\n        # Calculate Lightness\n        L = (max_val + min_val) / 2\n\n        # Calculate Saturation\n        if delta == 0:\n            S = 0  # It's a shade of gray, so no saturation\n            H = 0  # Hue is undefined for gray, but we can set it to 0\n        else:\n            if L < 0.5:\n                S = delta / (max_val + min_val)\n            else:\n                S = delta / (2.0 - max_val - min_val)\n\n            # Calculate Hue\n            if max_val == r:\n                H = ((g - b) / delta) % 6\n            elif max_val == g:\n                H = (b - r) / delta + 2\n            elif max_val == b:\n                H = (r - g) / delta + 4\n\n            H *= 60  # Convert hue to degrees\n\n            if H < 0:\n                H += 360\n\n        return int(round(H)), int(round(S * 100)), int(round(L * 100))\n\n    @staticmethod\n    def hsl_to_hex(h: int, s: int, l: int) -> str:\n        # Convert the saturation and lightness percentages to a fraction of 1\n        s /= 100\n        l /= 100\n\n        # Calculate C, X, and m\n        C = (1 - abs(2 * l - 1)) * s  # Chroma\n        X = C * (1 - abs((h / 60) % 2 - 1))  # Intermediate value based on hue\n        m = l - C / 2  # Lightness adjustment\n\n        # Calculate r', g', b' (primed values)\n        if 0 <= h < 60:\n            r_prime, g_prime, b_prime = C, X, 0\n        elif 60 <= h < 120:\n            r_prime, g_prime, b_prime = X, C, 0\n        elif 120 <= h < 180:\n            r_prime, g_prime, b_prime = 0, C, X\n        elif 180 <= h < 240:\n            r_prime, g_prime, b_prime = 0, X, C\n        elif 240 <= h < 300:\n            r_prime, g_prime, b_prime = X, 0, C\n        elif 300 <= h < 360:\n            r_prime, g_prime, b_prime = C, 0, X\n        else:\n            raise ValueError(\"Hue value must be in range [0, 360)\")\n\n        # Convert r', g', b' to the range [0, 255]\n        r = round((r_prime + m) * 255)\n        g = round((g_prime + m) * 255)\n        b = round((b_prime + m) * 255)\n\n        # Convert RGB to hex\n        return \"#{:02X}{:02X}{:02X}\".format(r, g, b)\n\n    def __create_lightness_range(self, starting_lightness: int, n_colors: int) -> list:\n        # Make `n_colors` number of linearly spaced lightness values between thr provided starting color\n        # and max allowed lightness\n        spaced_values = np.linspace(starting_lightness, self.max_palette_lightness, n_colors)\n        lightness = np.round(spaced_values).astype(int)\n        return lightness\n\n    def create_hex_code_palette(self, starting_hex: str, n_colors: int) -> list:\n        # Convert HEX to HSL\n        starting_hsl = self.hex_to_hsl(hex_color=starting_hex)\n        # Check if HSL is valid\n        is_valid_starting_hex = self.__validate_starting_lightness(starting_lightness=starting_hsl[2])\n\n        # Proceed only if the starting HSL is valid\n        if is_valid_starting_hex:\n            palette = []\n            lightness_range = self.__create_lightness_range(starting_lightness=starting_hsl[2], n_colors=n_colors)\n            for lightness in lightness_range:\n                # Keep hue and saturation identical\n                h = starting_hsl[0]\n                s = starting_hsl[1]\n                # Only change the lightness\n                curr_hex = self.hsl_to_hex(h=h, s=s, l=lightness)\n                palette.append(curr_hex)\n\n            return palette\n\n        raise ValueError(\"Given starting color is too light to construct a palette. Please choose a darker shade.\")\n\n    @staticmethod\n    def create_matplotlib_palette(colors: list, palette_name: str) -> mpl.colors.ListedColormap:\n        return mpl.colors.ListedColormap(\n            name=palette_name,\n            colors=colors\n        )\n```\n\nUp next, let's see what goes into using this class.\n## How to Use the MonochromePaletteGenerator class\nYou can create an object from the class like you normally would:\npython\n\n```\npalette_generator = MonochromePaletteGenerator()\n```\n\nNo parameters are required, as `max_palette_lightness` has a default value.\nTo create a blue monochrome palette, provide a dark enough starting hex color code and the number of colors. From there, you can also convert the generated palette into a Matplotlib format:\npython\n\n```\nmonochrome_blue = palette_generator.create_hex_code_palette(starting_hex=\"#051923\", n_colors=10)\nmonochrome_blue_mpl = palette_generator.create_matplotlib_palette(colors=monochrome_blue, palette_name=\"custom-monochrome-blue\")\n\nprint(monochrome_blue)\nmonochrome_blue_mpl\n```\n\n![Image 2 - Monochrome blue color palette \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1t5nkqSXge7Yj9WsXIi8m5A.png)\nImage 2 - Monochrome blue color palette (image by author)\nIt works with other colors as well. For example, you can use the following snippet to create a monochrome red palette:\npython\n\n```\nmonochrome_red = palette_generator.create_hex_code_palette(starting_hex=\"#1c0000\", n_colors=7)\nmonochrome_red_mpl = palette_generator.create_matplotlib_palette(colors=monochrome_red, palette_name=\"custom-monochrome-red\")\n\nprint(monochrome_red)\nmonochrome_red_mpl\n```\n\n![Image 3 - Monochrome red color palette \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/13tA5Fs_zYJrV-Tm1cFz07Q.png)\nImage 3 - Monochrome red color palette (image by author)\nThe `create_hex_code_palette()` will fail if the starting color is too bright, as you can see from the following example:\npython\n\n```\nwont_work_green = palette_generator.create_hex_code_palette(starting_hex=\"#1b663e\", n_colors=12)\n```\n\n![Image 4 - Exception raised with a too bright starting color \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1ah-ZYN_Fk6jGUa72vVU1ig.png)\nImage 4 - Exception raised with a too bright starting color (image by author)\nThe best way to see your color palettes in action is with charts.\n## Monochrome Color Palettes in Action\nUse the following snippet to create a made-up dataset of employee counts per location and department:\npython\n\n```\ndf = pd.DataFrame({\n    \"HR\": [50, 63, 40, 68, 35],\n    \"Engineering\": [77, 85, 62, 89, 58],\n    \"Marketing\": [50, 35, 79, 43, 67],\n    \"Sales\": [59, 62, 33, 77, 72],\n    \"Customer Service\": [31, 34, 61, 70, 39],\n    \"Distribution\": [35, 21, 66, 90, 31],\n    \"Logistics\": [50, 54, 13, 71, 32],\n    \"Production\": [22, 51, 54, 28, 40],\n    \"Maintenance\": [50, 32, 61, 69, 50],\n    \"Quality Control\": [20, 21, 88, 89, 39]\n}, index=[\"New York\", \"San Francisco\", \"Los Angeles\", \"Chicago\", \"Miami\"])\n\ndf = df.T\ndf = df.loc[df.sum(axis=1).sort_values().index]\n\ndf\n```\n\n![Image 5 - Dummy employee dataset \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1X1CsSTTplghUZHgd_IpASw.png)\nImage 5 - Dummy employee dataset (image by author)\nThere are 5 office locations and 10 departments - an ideal situation for a stacked horizontal bar chart!\nYou can pass your custom color palette to the `colormap` parameter:\npython\n\n```\nax = df.plot(kind=\"barh\", colormap=monochrome_blue_mpl, width=0.8, edgecolor=\"#000000\", stacked=True)\n\nplt.title(\"Employee Count Per Location And Department\", loc=\"left\", fontdict={\"weight\": \"bold\"}, y=1.06)\nplt.xlabel(\"Office Location\")\nplt.ylabel(\"Count\")\n\nplt.show()\n```\n\n![Image 6 - Chart with a blue monochromatic color palette \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1-qxDudCBzZfQq9rJK0CIkQ.png)\nImage 6 - Chart with a blue monochromatic color palette (image by author)\nThe same code works with the monochrome red palette - just change the `colormap` value:\ngraphql\n\n```\nax = df.plot(kind=\"barh\", colormap=monochrome_red_mpl, width=0.8, edgecolor=\"#000000\", stacked=True)\n\nplt.title(\"Employee Count Per Location And Department\", loc=\"left\", fontdict={\"weight\": \"bold\"}, y=1.06)\nplt.xlabel(\"Office Location\")\nplt.ylabel(\"Count\")\n\nplt.show()\n```\n\n![Image 7 - Chart with a red monochromatic color palette \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1_wESUm79BotDXEhQCB_uRg.png)\nImage 7 - Chart with a red monochromatic color palette (image by author)\nLong story short - it works like a charm - it just needs a dark enough color to start.\n## Wrapping up\nTo conclude, a bit of Python code can go a long way.\nUsually, to create a monochrome color palette, you'd search online or start with a color you like and adjust the lightness until you get enough variations. Today, you've learned how to automate this process.\nYou can expand this by adding default starting colors, so you don't need to choose one each time. But that part is simple and I'll leave it to you.\nUntil next time.\n-Dario\n[_Looking to level up your data visualization game? Join thousands of like-minded people on my Substack for expert tips and exclusive content._](https://darioradecic.substack.com/)\n> [**Data Doodles with Python | Dario Radecic | Substack**](https://darioradecic.substack.com/)\n* * *\n_Originally published at_[ _https://darioradecic.substack.com_](https://darioradecic.substack.com/p/how-to-convert-a-single-hex-color) _._\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657095692_93hujy.png)\nWritten By\n## [Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nhttps://writingfordevs.substack.com\n[See all from Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\n[Color Palette](https://towardsdatascience.com/tag/color-palette/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Data Visualization](https://towardsdatascience.com/tag/data-visualization/)[Programming](https://towardsdatascience.com/tag/programming/)[Python](https://towardsdatascience.com/tag/python/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de%2F&title=How%20to%20Convert%20a%20Single%20HEX%20Color%20Code%20into%20a%20Monochrome%20Color%20Palette%20with%20Python)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de%2F&title=How%20to%20Convert%20a%20Single%20HEX%20Color%20Code%20into%20a%20Monochrome%20Color%20Palette%20with%20Python)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de%2F&text=How%20to%20Convert%20a%20Single%20HEX%20Color%20Code%20into%20a%20Monochrome%20Color%20Palette%20with%20Python)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/07/0hmjgJ_f9zS9o0lhP-scaled.jpg)](https://towardsdatascience.com/how-to-schedule-a-serverless-google-cloud-function-to-run-periodically-249acf3a652e/)\n## [How to Schedule a Serverless Google Cloud Function to Run Periodically](https://towardsdatascience.com/how-to-schedule-a-serverless-google-cloud-function-to-run-periodically-249acf3a652e/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nDo you have some code that needs to be run regularly?\n[Saed Hussain](https://towardsdatascience.com/author/saedhussain/)\nJuly 4, 20218 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/06/1IgmUgJ247jUZqarNYReLFA.gif)](https://towardsdatascience.com/text-network-analysis-theory-and-practice-223ac81c5f07/)\n## [Text Network Analysis: Theory and Practice](https://towardsdatascience.com/text-network-analysis-theory-and-practice-223ac81c5f07/)\n[](https://towardsdatascience.com/how-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de/)\nText network analysis belongs to the broader skill set of most text data-oriented analysts.\n[Petr Koráb](https://towardsdatascience.com/author/petrkorab/)\nJune 5, 20226 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/1oRXwKEY936R59enMEWROQw.jpeg)](https://towardsdatascience.com/you-must-know-python-json-dumps-but-maybe-not-all-aspects-fa8d98a76aa0/)\n## [You Must Know Python JSON Dumps, But Maybe Not All Aspects](https://towardsdatascience.com/you-must-know-python-json-dumps-but-maybe-not-all-aspects-fa8d98a76aa0/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nSome tricks about the dump(s) method of the Python JSON module\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nDecember 6, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/0HLXX7OJMZyUiHjzz-scaled.jpg)](https://towardsdatascience.com/can-you-trust-your-model-when-data-shifts-981ed681f1fd/)\n## [Can you trust your model when data shifts?](https://towardsdatascience.com/can-you-trust-your-model-when-data-shifts-981ed681f1fd/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nIn real-case applications, machine learning is not as common as we would expect: let's explore why.\n[Laura Gorrieri](https://towardsdatascience.com/author/laura-gorrieri/)\nDecember 23, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/04/1vgrkCK7-VLWBpmuKOWScZw.png)](https://towardsdatascience.com/whats-the-difference-between-a-data-scientist-research-scientist-and-an-applied-scientist-30c04190c1fa/)\n## [What's the Difference Between a Data Scientist, Research Scientist, and an Applied Scientist?](https://towardsdatascience.com/whats-the-difference-between-a-data-scientist-research-scientist-and-an-applied-scientist-30c04190c1fa/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nDemystifying the similarities and differences between data science roles\n[Terence Shin, MSc, MBA](https://towardsdatascience.com/author/terenceshin/)\nApril 30, 20203 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/10/0peyDOnTXNRWrETyO-scaled.jpg)](https://towardsdatascience.com/upgrading-to-prefect-push-workers-on-aws-ecs-64c5b5c11d0c/)\n## [Upgrading to Prefect Push Workers on AWS ECS](https://towardsdatascience.com/upgrading-to-prefect-push-workers-on-aws-ecs-64c5b5c11d0c/)\n[Data Engineering](https://towardsdatascience.com/category/data-science/data-engineering/)\nUpgrade from Prefect 2.0 to 3.0 and use the new Push Work Pools that greatly simplify infrastructure management and reduce cost.\n[Brian Roepke](https://towardsdatascience.com/author/broepke/)\nOctober 12, 20246 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/0V-cj1QKSSOJ24Hcn-scaled.jpg)](https://towardsdatascience.com/a-physicists-view-of-machine-learning-the-thermodynamics-of-machine-learning-6a3ab00e46f1/)\n## [A Physicist's View of Machine Learning: The Thermodynamics of Machine Learning](https://towardsdatascience.com/a-physicists-view-of-machine-learning-the-thermodynamics-of-machine-learning-6a3ab00e46f1/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nComplex systems in nature can be successfully studied using thermodynamics. What about Machine Learning?\n[Tim Lou, PhD](https://towardsdatascience.com/author/tim-lou/)\nApril 18, 20229 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1CQeSkWLvgF03J-bmbF93xA-scaled.jpeg)](https://towardsdatascience.com/how-to-build-an-efficient-and-modern-data-platform-7e0e7630ef70/)\n## [How to build an efficient and modern Data Platform](https://towardsdatascience.com/how-to-build-an-efficient-and-modern-data-platform-7e0e7630ef70/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nWhy you should integrate Data Lakes, Warehouses and Marts in each other rather than silo them\n[Christianlauer](https://towardsdatascience.com/author/christianlauer90/)\nJune 18, 20214 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/1IL0TaIk5KbB5PNWX4aiv1w.png)](https://towardsdatascience.com/anchors-away-more-python-regular-expressions-you-wish-you-knew-8a7780ac54e9/)\n## [Anchors Away! More Python Regular Expressions You Wish You Knew](https://towardsdatascience.com/anchors-away-more-python-regular-expressions-you-wish-you-knew-8a7780ac54e9/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nSecrets to working with text using advanced regular expressions tools in Python\n[Drew Seewald](https://towardsdatascience.com/author/realdrewdata/)\nOctober 26, 202011 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\nword word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word\n  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1\n",
  "metadata": {
    "title": "How to Convert a Single HEX Color Code into a Monochrome Color Palette with Python | Towards Data Science",
    "description": "Spoiler: It's harder than you think.",
    "keywords": null,
    "author": "Dario Radečić",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "How to Convert a Single HEX Color Code into a Monochrome Color Palette with Python",
    "og:description": "Spoiler: It's harder than you think.",
    "og:url": "https://towardsdatascience.com/how-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1din5xskMRGuBgjQ7pejM5A.png",
    "og:image:width": "1500",
    "og:image:height": "1000",
    "og:image:type": "image/png",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Dario Radečić",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "8 min read",
    "article:published_time": "2024-09-27T04:11:20.000Z",
    "article:modified_time": "2024-09-27T04:11:20.000Z",
    "article:author": "https://towardsdatascience.com/author/radecicdario/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": "",
    "retried": true
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_000.txt",
      "chars": 96
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_001.txt",
      "chars": 39
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_002.txt",
      "chars": 4513
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_003.txt",
      "chars": 49
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_004.txt",
      "chars": 270
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_005.txt",
      "chars": 263
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_006.txt",
      "chars": 97
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_007.txt",
      "chars": 557
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_008.txt",
      "chars": 270
    },
    {
      "language": "txt",
      "file": "attachments/2efaaf940ede/code/block_009.txt",
      "chars": 269
    }
  ],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1din5xskMRGuBgjQ7pejM5A.png",
      "alt": "Article thumbnail (image by author)",
      "local_path": "attachments/2efaaf940ede/images/000.png",
      "bytes": 9413,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1ifmH8wu-vEibMMsLZFIbVg.png",
      "alt": "Image 1 - Hex color code in different color models (image by author)",
      "local_path": "attachments/2efaaf940ede/images/001.png",
      "bytes": 292800,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1t5nkqSXge7Yj9WsXIi8m5A.png",
      "alt": "Image 2 - Monochrome blue color palette (image by author)",
      "local_path": "attachments/2efaaf940ede/images/002.png",
      "bytes": 16176,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/13tA5Fs_zYJrV-Tm1cFz07Q.png",
      "alt": "Image 3 - Monochrome red color palette (image by author)",
      "local_path": "attachments/2efaaf940ede/images/003.png",
      "bytes": 12689,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1ah-ZYN_Fk6jGUa72vVU1ig.png",
      "alt": "Image 4 - Exception raised with a too bright starting color (image by author)",
      "local_path": "attachments/2efaaf940ede/images/004.png",
      "bytes": 75950,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1X1CsSTTplghUZHgd_IpASw.png",
      "alt": "Image 5 - Dummy employee dataset (image by author)",
      "local_path": "attachments/2efaaf940ede/images/005.png",
      "bytes": 65076,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1-qxDudCBzZfQq9rJK0CIkQ.png",
      "alt": "Image 6 - Chart with a blue monochromatic color palette (image by author)",
      "local_path": "attachments/2efaaf940ede/images/006.png",
      "bytes": 209633,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1_wESUm79BotDXEhQCB_uRg.png",
      "alt": "Image 7 - Chart with a red monochromatic color palette (image by author)",
      "local_path": "attachments/2efaaf940ede/images/007.png",
      "bytes": 209309,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/07/0hmjgJ_f9zS9o0lhP-scaled.jpg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/008.jpg",
      "bytes": 401362,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/06/1IgmUgJ247jUZqarNYReLFA.gif",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/009.gif",
      "bytes": 12398967,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/1oRXwKEY936R59enMEWROQw.jpeg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/010.jpeg",
      "bytes": 212691,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/0HLXX7OJMZyUiHjzz-scaled.jpg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/011.jpg",
      "bytes": 263098,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/04/1vgrkCK7-VLWBpmuKOWScZw.png",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/012.png",
      "bytes": 490614,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/10/0peyDOnTXNRWrETyO-scaled.jpg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/013.jpg",
      "bytes": 530316,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/0V-cj1QKSSOJ24Hcn-scaled.jpg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/014.jpg",
      "bytes": 376719,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1CQeSkWLvgF03J-bmbF93xA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/015.jpeg",
      "bytes": 527761,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/1IL0TaIk5KbB5PNWX4aiv1w.png",
      "alt": "",
      "local_path": "attachments/2efaaf940ede/images/016.png",
      "bytes": 45115,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [],
  "links": [],
  "retry_at": "2026-10-03T07:58:07",
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:48Z",
  "source_url": "https://towardsdatascience.com/how-to-convert-a-single-hex-color-code-into-a-monochrome-color-palette-with-python-0bf7741029de/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}