LoginSignup
35
26

More than 5 years have passed since last update.

Matplotlibのグラフの色を同系色で揃える(カラーマップ)

Posted at

デモ

カラーマップなし カラーマップあり
colorful.png Blues.png

方法

連続的なデータを扱うなら、カラーマップを利用することで美しいグラフを作成することができます。

カラーマップはplt.get_cmap()で取得します。取得したカラーマップに数値(0.0 ~ 1.0)を渡すことで、そのカラーマップ内の色を使うことができます。

demo.py
import numpy as np
import matplotlib.pyplot as plt

N = 16

x = np.arange(0, 4, 0.01)
y = [i * np.sin(x)**2 for i in xrange(N)]
cmap = plt.get_cmap("Blues")

for i in xrange(len(y)):
    plt.plot(x, y[i], c=cmap(float(i)/N))

plt.show()

サンプル(一部)

Reds Greens Blues binary
Reds.png Greens.png Blues.png binary.png
spring summer autumn winter
spring.png summer.png autumn.png winter.png

その他のカラーマップはこちら

参考

matplotlib:自動で色分け - Qiita
http://qiita.com/konnyakmannan/items/ab297d53afd9dc94e0e8

color example code: colormaps_reference.py — Matplotlib 1.5.3 documentation
http://matplotlib.org/examples/color/colormaps_reference.html

現在のカラーマップの表示と設定 - MATLAB colormap - MathWorks 日本
http://jp.mathworks.com/help/matlab/ref/colormap.html

35
26
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
26