{"id":7991,"library":"brewer2mpl","title":"brewer2mpl","description":"brewer2mpl is a Python package that provides access to the ColorBrewer2.org color maps. It allows users to retrieve sequential, diverging, and qualitative color palettes in various formats, including RGB 0-255, hex strings, and 0-1 normalized RGB triplets suitable for Matplotlib. The library is no longer actively maintained; its functionality has been superseded by the `Palettable` library. The current version is 1.4.1, released in 2014, and there are no further updates planned.","status":"deprecated","version":"1.4.1","language":"en","source_language":"en","source_url":"https://github.com/jiffyclub/brewer2mpl","tags":["colors","colorbrewer","matplotlib","visualization","deprecated"],"install":[{"cmd":"pip install brewer2mpl","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for integration with plotting functionalities, especially when converting palettes to Matplotlib colormaps (e.g., via `bmap.mpl_colormap` or `bmap.mpl_colors`). While brewer2mpl itself has no hard dependencies, its primary use case involves Matplotlib.","package":"matplotlib","optional":true}],"imports":[{"symbol":"brewer2mpl","correct":"import brewer2mpl"},{"note":"The `get_map` function requires three arguments: map name, map type ('Sequential', 'Diverging', or 'Qualitative'), and the number of colors.","wrong":"bmap = brewer2mpl.get_map('Set1', 5)","symbol":"get_map","correct":"bmap = brewer2mpl.get_map('Set1', 'Qualitative', 5)"},{"note":"Direct access to color maps is available via `sequential`, `diverging`, and `qualitative` modules, which contain dictionaries of `BrewerMap` objects keyed by the number of colors.","symbol":"sequential","correct":"from brewer2mpl.sequential import Blues"}],"quickstart":{"code":"import brewer2mpl\nimport matplotlib.pyplot as plt\n\n# Get a qualitative color map named 'Set2' with 7 colors\nbmap = brewer2mpl.get_map('Set2', 'Qualitative', 7)\n\n# Access colors as 0-1 RGB triplets for Matplotlib\ncolors_for_mpl = bmap.mpl_colors\n\nprint(f\"Color map name: {bmap.name}\")\nprint(f\"Number of colors: {bmap.number}\")\nprint(f\"Matplotlib compatible colors (0-1 RGB): {colors_for_mpl}\")\n\n# Example of using colors in a Matplotlib plot (if matplotlib is installed)\n# plt.figure(figsize=(7, 1))\n# for i, color in enumerate(colors_for_mpl):\n#     plt.barh(0, 1, left=i, color=color)\n# plt.axis('off')\n# plt.title('Brewer2mpl Set2 Qualitative (7 colors)')\n# plt.show()","lang":"python","description":"This quickstart demonstrates how to fetch a named qualitative color map, access its Matplotlib-compatible RGB colors (0-1 range), and print relevant information. The commented-out Matplotlib plotting code shows a simple way to visualize the retrieved colors."},"warnings":[{"fix":"Migrate to `Palettable`: `pip install palettable`. Update import statements (e.g., `from palettable.colorbrewer.qualitative import Set2_7` instead of `brewer2mpl.get_map('Set2', 'Qualitative', 7)`).","message":"The `brewer2mpl` library is no longer actively maintained or updated. Its development ceased in 2014, and it has been officially superseded by the `Palettable` library. Users are strongly encouraged to migrate to `Palettable` for ongoing support, new features, and broader palette options.","severity":"deprecated","affected_versions":"1.0.0 and above"},{"fix":"For discrete color lists in Matplotlib, use `bmap.mpl_colors`. For a continuous colormap object, use `bmap.mpl_colormap`. Avoid using `bmap.colors` directly with Matplotlib functions that expect normalized values, as this will lead to incorrect color rendering.","message":"When working with Matplotlib, ensure you use the correct color representation from a `BrewerMap` object. `bmap.colors` provides RGB as 0-255 integer triplets, while `bmap.mpl_colors` provides RGB as 0-1 float triplets, which is the standard expected by Matplotlib functions for discrete colors. `bmap.mpl_colormap` provides a `matplotlib.colors.LinearSegmentedColormap` object for continuous usage.","severity":"gotcha","affected_versions":"1.0.0 and above"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade to a newer Python 2.x version (2.7+) or Python 3.x. If stuck on Python 2.6, manually edit `brewer2mpl.py` (line 151) to replace `{:>02}` with `{0:>02}`.","cause":"This error specifically occurred in Python 2.6 due to a change in string formatting syntax. It was encountered when `brewer2mpl` used `{:>02}` which is not supported in Python 2.6.","error":"ValueError: zero length field name in format"},{"fix":"Always verify the correct map name, type (case-sensitive 'Sequential', 'Diverging', 'Qualitative'), and the available number of colors by checking the ColorBrewer2.org website or using `brewer2mpl.print_maps()` to list available options.","cause":"This error occurs when `brewer2mpl.get_map()` is called with an invalid color map name, an incorrect type (e.g., 'Qualitative' when the map is 'Sequential'), or a number of colors not available for that specific map/type combination. ColorBrewer2 maps have specific names, types, and a limited range of available color counts (e.g., 3-12 colors).","error":"KeyError: ('Invalid color map or type', 'NonExistentMap', 'Qualitative', 5)"}]}