A python package for mapping
Project description
multicolor
A Python package for colormap management and batch plotting.
- Free software: MIT License
- Documentation: https://zbhgis.github.io/multicolor
Features
- 色带数据库 — 基于 SQLite 内置 12 条色带,支持按类型、标签、色盲兼容性、关键词筛选
- 色带工厂 — 从数据库一键生成
matplotlibColormap 对象(Sequential / Diverging / Qualitative) - 自定义色带 — 用户可添加自己的色带,内置色带受保护不可覆盖
- 自动同步 — 升级包时自动同步新版内置色带,同时保留用户自定义内容
- 装饰器批量绘图 —
@batch_cmaps一键将同一绘图函数应用到多个色带 - 多子图导出 — 支持 single(独立窗口)和 grid(单图多子图)两种布局
Installation
稳定版
pip install multicolor
开发版
pip install git+https://github.com/zbhgis/multicolor.git
环境要求
- Python >= 3.10
- 依赖:
cartopy>=0.25.0,matplotlib>=3.10.0,numpy>=1.24.0
Quick Start
获取色带
from multicolor import cmap
# 按名称获取
viridis = cmap.get("Viridis")
# 按 ID 获取
cm = cmap.get_by_id(1)
筛选与查询
# 按类型
names = cmap.names(cmap_type="sequential")
# 按色盲兼容性
names = cmap.names(colorblind_safe="any")
# 只看内置色带(排除用户自定义)
names = cmap.names(is_custom=False)
# 只看用户自定义色带
names = cmap.names(is_custom=True)
# 关键词搜索
cmap.list(keyword="temperature")
添加自定义色带
cmap.add(
name="MyCmap",
colors=["#ff0000", "#00ff00", "#0000ff"],
cmap_type="sequential",
tags=["custom"],
colorblind_safe="none",
description="my custom colormap",
)
装饰器批量绘图
from multicolor import cmap, batch_cmaps
# 方式 1:直接指定名称列表
@batch_cmaps(["Viridis", "Plasma", "Inferno"])
def draw(cmap_obj):
cmap.preview(cmap_obj)
# 方式 2:动态查询筛选
@batch_cmaps(query_func=lambda: cmap.names(cmap_type="diverging"))
def draw_all_diverging(cmap_obj):
cmap.preview(cmap_obj)
# 方式 3:grid 布局(所有色带画在一张图上)
@batch_cmaps(
query_func=lambda: cmap.names(colorblind_safe="any", limit=6),
layout="grid",
cols=3
)
def draw_grid(cmap_obj, ax=None):
ax.imshow(data, cmap=cmap_obj)
draw()
draw_all_diverging()
draw_grid()
结合 Cartopy 绘制地图
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from multicolor import cmap, batch_cmaps
@batch_cmaps(query_func=lambda: cmap.names(cmap_type="sequential"))
def draw_map(cmap_obj):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.coastlines()
ax.imshow(data, cmap=cmap_obj, transform=ccrs.PlateCarree())
plt.savefig(f"map_{cmap_obj.name}.png")
plt.close()
draw_map()
内置色带
| ID | Name | Type | Colorblind Safe |
|---|---|---|---|
| 1 | RdYlGn | diverging | deutan, protan |
| 2 | Viridis | sequential | deutan, protan, tritan |
| 3 | CoolWarm | diverging | deutan |
| 4 | Terrain | diverging | - |
| 5 | NightLights | sequential | - |
| 6 | LandUse | qualitative | - |
| 7 | Plasma | sequential | deutan |
| 8 | RdBu | diverging | deutan |
| 9 | Inferno | sequential | deutan, protan |
| 10 | Cividis | sequential | deutan, protan, tritan, achromatopsia |
| 11 | Precip | sequential | deutan |
| 12 | Elevation | sequential | - |
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multicolor-0.0.4.tar.gz
(53.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multicolor-0.0.4.tar.gz.
File metadata
- Download URL: multicolor-0.0.4.tar.gz
- Upload date:
- Size: 53.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9011ab578d47256528c8b59ca929339cda41cbadfc28ec083e1dd5263485589d
|
|
| MD5 |
b8d049614f631c3f89602b926634d977
|
|
| BLAKE2b-256 |
5c8a46712ee4c8647a21838bc07a581f0ef9cf70a16a51d13cbcf9772e900c94
|
File details
Details for the file multicolor-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: multicolor-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25778d6cdd3fdeb4cbf296b51e5e605c84de0aeed39cfb52f1532a3f46de64a7
|
|
| MD5 |
cec239e0418e1084f3ad7fbfd0eb6d6f
|
|
| BLAKE2b-256 |
8a57bc8d0d255dd2612909d60a3591f7f4734a9555f12d81b50c7ef59dcb3443
|