반응형

Choosing Colormaps in Matplotlib

https://matplotlib.org/stable/tutorials/colors/colormaps.html

 

Choosing Colormaps in Matplotlib — Matplotlib 3.5.1 documentation

Colormaps are often split into several categories based on their function (see, e.g., [Moreland]): First, we'll show the range of each colormap. Note that some seem to change more "quickly" than others. Sequential2 Many of the \(L^*\) values from the Seque

matplotlib.org

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cm
from colorspacious import cspace_converter
cmaps = {}

gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(category, cmap_list):
    # Create figure and adjust figure height to number of colormaps
    nrows = len(cmap_list)
    figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
    fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh))
    fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,
                        left=0.2, right=0.99)
    axs[0].set_title(f'{category} colormaps', fontsize=14)

    for ax, name in zip(axs, cmap_list):
        ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,
                transform=ax.transAxes)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axs:
        ax.set_axis_off()

    # Save colormap list for later.
    cmaps[category] = cmap_list

 

plot_color_gradients('Perceptually Uniform Sequential',
                     ['viridis', 'plasma', 'inferno', 'magma', 'cividis'])

plot_color_gradients('Sequential',
                     ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
                      'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                      'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'])

 

 

 

 

 

반응형
반응형

matplotlib colormap

colormap에 대한 설명을 찾기가 어렵다.
자세하게 설명을 붙여서 정리하고 싶은데, colormap 사용법은 많은데 설명은 없다.
matplotlib 소스코드를 분석하는 중에
colormap을 알아야 하는 상황에 처하게 되서 부족하지만 정리해 본다.

 

내가 생각할 때는
숫자를 색상에 매핑시키기 위한 색상 지도이다.
다만 테이블처럼 2차원 형태가 아니라 30cm 자와 같이 1차원 형태의 색상 배열이다.

갖고 있는 데이터를 그래프에 표시할 때
일반적인 색상을 사용해서 표시하는 것은 의미가 없다.
데이터를 색상으로 표현하는 것은 말이 되지 않는다.
그러나, 잘 정리된 colormap을 사용한다면 시각적으로 엄청난 효과를 거둘 수 있다.

가령, 지구를 평균 기온에 따라 표현한다고 했을 때
추운 지역은 파란색으로, 더운 지역은 빨간색으로 표시할 수 있다.
결국 지구상의 모든 영역은 파랑과 빨강이 연결된 그라데이션에 포함된 어떤 색상이 된다.
이와 같이 특정 데이터에 대해 사용될 수 있는 색상표를 colormap이라고 부른다.

 

# matplotlib 도움말

 

# 과학 데이터를 표시하기에 적합한 colormap 모음.
미국 지도에 인구 밀도에 따른 색상으로 표시한 그래픽은 압권.

 

# colormap 한글 설명.
많은 설명은 아니지만, 일부 매핑에 대해 상세한 설명을 제공한다.



출처: https://pythonkim.tistory.com/82 [파이쿵]

반응형

+ Recent posts