MatPlotLib修改自定义线性分段色彩图

时间:2016-08-11 18:43:06

标签: python-3.x matplotlib

关于对this question的接受回复:

如果我想使用3种或更多不同的自定义颜色怎么办?是否可以轻松编辑LinearSegmentedColormap?

这适用于2:

import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

shpfile = 'cb_2015_us_county_20m.shp'
c = gpd.read_file(shpfile)
c = c.loc[c['GEOID'].isin(['26161','26093','26049','26091','26075',
                           '26125','26163','26099','26115','26065'])]

c['color'] = np.zeros(len(c))
# 23 is index for Washtenaw county and 1992 is index for Wayne county
c.ix[23, 'color'] = 1.0
c.ix[1992, 'color'] = 1.0

# create simple linear colormap that maps grey to blue
cmap = LinearSegmentedColormap.from_list(
    'mycmap', [(0, 'grey'), (1, 'blue')])

c.plot(column='color', cmap=cmap)

3,我试过了:

cmap = LinearSegmentedColormap.from_list(
    'mycmap', [(0, 'grey'), (0.5, 'red'), (1, 'blue')])

提前致谢!

0 个答案:

没有答案