[PYTHON] Align Matplotlib graph colors with similar colors (color map)

demo

No color map There is a color map
colorful.png Blues.png

Method

If you are dealing with continuous data, you can create beautiful graphs by using color maps.

The color map is obtained with plt.get_cmap (). By passing a numerical value (0.0 to 1.0) to the acquired color map, you can use the colors in that color map.

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()

Sample (part)

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

Click here for other colormaps (http://matplotlib.org/examples/color/colormaps_reference.html)

reference

matplotlib: Automatically color coded --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

Displaying and setting the current colormap - MATLAB colormap --MathWorks Japan http://jp.mathworks.com/help/matlab/ref/colormap.html

Recommended Posts

Align Matplotlib graph colors with similar colors (color map)
Band graph with matplotlib
Graph Excel data with matplotlib (1)
Graph drawing method with matplotlib
matplotlib gallery and color map
Graph Excel data with matplotlib (2)
Gradient color selection with matplotlib
Draw a loose graph with matplotlib
Manipulate colors with pip install color
Continuously color with matplotlib scatter plot
[Python] Set the graph range with matplotlib
Specify the color in the matplotlib 2D map
Align the size of the colorbar with matplotlib
Heat Map for Grid Search with Matplotlib
Set the xticklabels color individually with matplotlib
Graph trigonometric functions with numpy and matplotlib
Create a graph with borders removed with matplotlib
Draw a flat surface with a matplotlib 3d graph
[Python] limit axis of 3D graph with Matplotlib
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Increase the font size of the graph with matplotlib
Draw a graph with matplotlib from a csv file
Graph drawing with jupyter (ipython notebook) + matplotlib + vagrant
Visualize grib2 on a map with python (matplotlib)
Animation with matplotlib
Japanese with matplotlib
matplotlib graph album
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
[Python] How to draw a line graph with Matplotlib
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
How to plot a lot of legends by changing the color of the graph continuously with matplotlib