The following command is important to view matplotlib plots on a jupyter notebook
In [1]:
# %matplotlib inline
In [2]:
%matplotlib notebook
In [3]:
import matplotlib.pyplot as plt
In [4]:
from mpl_toolkits.mplot3d import Axes3D
In [5]:
import os, sys
In [6]:
from matplotlib.mlab import griddata
In [7]:
import numpy as np
In [8]:
from pylab import *
In [9]:
cdict = {'red': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.7),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 1.0, 1.0)),
'blue': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 0.5, 1.0))}
In [10]:
my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256)
In [11]:
pcolor(rand(10,10),cmap=my_cmap)
colorbar()
Out[11]:
where rand(10,10) is a 10x10 array of random numbers in the range $[0.0, 1.0)$
In [12]:
rand(10,10)
Out[12]:
In [13]:
cdict2 = {'red': ((0.0, 0.0, 0.0),
(0.3, 0.5, 0.5),
(0.6, 0.7, 0.7),
(0.9, 0.8, 0.8),
(1.0, 0.8, 0.8)),
'green': ((0.0, 0.0, 0.0),
(0.3, 0.8, 0.8),
(0.6, 0.7, 0.7),
(0.9, 0.0, 0.0),
(1.0, 0.7, 0.7)),
'blue': ((0.0, 1.0, 1.0),
(0.3, 1.0, 1.0),
(0.6, 0.0, 0.0),
(0.9, 0.0, 0.0),
(1.0, 1.0, 1.0))}
In [14]:
cmap1 = matplotlib.colors.LinearSegmentedColormap('my_colormap2', cdict2, N=256 )
In [15]:
cmap2 = matplotlib.colors.LinearSegmentedColormap('my_colormap2', cdict2, N=256, gamma=0.75 )
In [16]:
pcolor(rand(10,10),cmap=cmap1 )
colorbar()
Out[16]:
In [17]:
pcolor(rand(10,10),cmap=cmap2 )
colorbar()
Out[17]:
In [39]:
cdict3 = {'red': ((0.0, 1.0, 1.0),
(0.2,1.0, 1.0 ),
(0.4,0.0,0.0),
(0.6,0.0,0.0),
(0.8,0.0,0.0),
(1.0,1.0,1.0)),
'green': ((0.0,0.0,0.0),
(0.2,1.0,1.0),
(0.4,1.0,1.0),
(0.6,1.0,1.0),
(0.8,0.0, 0.0),
(1.0,0.0,0.0)),
'blue': ((0.0,0.0,0.0),
(0.2,0.0,0.0),
(0.4,0.0,0.0),
(0.6,1.0,1.0),
(0.8,1.0,1.0),
(1.0,1.0,1.0))}
In [35]:
cmap3 = matplotlib.colors.LinearSegmentedColormap('my_colormap3', cdict3, N=256)
In [36]:
pcolor(rand(10,10),cmap=cmap3)
colorbar()
Out[36]:
In [22]:
minval = -0.4
maxval = 1.6
rangeval = maxval - minval
In [26]:
rangeval*0.2
Out[26]:
In [27]:
"""
cdict3b = {'red': ((minval + rangeval*0.2*0, 1.0, 1.0),
(minval + rangeval*0.2*1,1.0, 1.0 ),
(minval + rangeval*0.2*2,0.0,0.0),
(minval + rangeval*0.2*3,0.0,0.0),
(minval + rangeval*0.2*4,1.0,0.0),
(minval + rangeval*0.2*5,1.0,1.0)),
'green': ((minval + rangeval*0.2*0,0.0,0.0),
(minval + rangeval*0.2*1,1.0,1.0),
(minval + rangeval*0.2*2,1.0,1.0),
(minval + rangeval*0.2*3,1.0,1.0),
(minval + rangeval*0.2*4,0.0, 0.0),
(minval + rangeval*0.2*5,0.0,0.0)),
'blue': ((minval + rangeval*0.2*0,0.0,0.0),
(minval + rangeval*0.2*1,0.0,0.0),
(minval + rangeval*0.2*2,0.0,0.0),
(minval + rangeval*0.2*3,0.0,1.0),
(minval + rangeval*0.2*4,1.0,1.0),
(minval + rangeval*0.2*5,1.0,1.0))}
"""
In [28]:
cdict3b
Out[28]:
In [40]:
cmap3b = matplotlib.colors.LinearSegmentedColormap('my_colormap3b', cdict3, N=256)
In [41]:
pcolor( np.random.uniform(minval, maxval, size=(10,10)),cmap=cmap3b)
colorbar()
Out[41]: