不幸的是,matplotlib没有提供Matlab的demcmap的功能。

实际上,python basemap包中可能有一些内置特性,我不知道这些特性。在

所以,坚持matplotlib板上的选项,我们可以子类^{}来构建一个以colormap中间的点为中心的颜色规范化。此技术可以在StackOverflow上的another question中找到,并根据具体需要进行调整,即设置sealevel(可能最好选择为0)和颜色映射col_val(范围在0和1之间)中的值,该值应与该sealevel对应。在地形图的情况下,0.22,对应于一个turqoise颜色,可能是一个不错的选择。

然后可以将Normalize实例作为imshow的参数。在图片的第一行下面可以看到结果图。在

由于海平面周围的平滑过渡,0周围的值显示为杂色,因此很难区分陆地和海洋。

因此,我们可以稍微改变一下地形图,去掉那些颜色,这样海岸线就更清晰可见了。这是通过地图的combining two parts来完成的,范围从0到0.17,从0.25到1,并因此切断了它的一部分。在import numpy as np

import matplotlib.pyplot as plt

import matplotlib.colors

class FixPointNormalize(matplotlib.colors.Normalize):

"""

Inspired by https://stackoverflow.com/questions/20144529/shifted-colorbar-matplotlib

Subclassing Normalize to obtain a colormap with a fixpoint

somewhere in the middle of the colormap.

This may be useful for a `terrain` map, to set the "sea level"

to a color in the blue/turquise range.

"""

def __init__(self, vmin=None, vmax=None, sealevel=0, col_val = 0.21875, clip=False):

# sealevel is the fix point of the colormap (in data units)

self.sealevel = sealevel

# col_val is the color value in the range [0,1] that should represent the sealevel.

self.col_val = col_val

matplotlib.colors.Normalize.__init__(self, vmin, vmax, clip)

def __call__(self, value, clip=None):

x, y = [self.vmin, self.sealevel, self.vmax], [0, self.col_val, 1]

return np.ma.masked_array(np.interp(value, x, y))

# Combine the lower and upper range of the terrain colormap with a gap in the middle

# to let the coastline appear more prominently.

# inspired by https://stackoverflow.com/questions/31051488/combining-two-matplotlib-colormaps

colors_undersea = plt.cm.terrain(np.linspace(0, 0.17, 56))

colors_land = plt.cm.terrain(np.linspace(0.25, 1, 200))

# combine them and build a new colormap

colors = np.vstack((colors_undersea, colors_land))

cut_terrain_map = matplotlib.colors.LinearSegmentedColormap.from_list('cut_terrain', colors)

# invent some data (height in meters relative to sea level)

data = np.linspace(-1000,2400,15**2).reshape((15,15))

# plot example data

fig, ax = plt.subplots(nrows = 2, ncols=3, figsize=(11,6) )

plt.subplots_adjust(left=0.08, right=0.95, bottom=0.05, top=0.92, hspace = 0.28, wspace = 0.15)

plt.figtext(.5, 0.95, "Using 'terrain' and FixedPointNormalize", ha="center", size=14)

norm = FixPointNormalize(sealevel=0, vmax=3400)

im = ax[0,0].imshow(data+1000, norm=norm, cmap=plt.cm.terrain)

fig.colorbar(im, ax=ax[0,0])

norm2 = FixPointNormalize(sealevel=0, vmax=3400)

im2 = ax[0,1].imshow(data, norm=norm2, cmap=plt.cm.terrain)

fig.colorbar(im2, ax=ax[0,1])

norm3 = FixPointNormalize(sealevel=0, vmax=0)

im3 = ax[0,2].imshow(data-2400.1, norm=norm3, cmap=plt.cm.terrain)

fig.colorbar(im3, ax=ax[0,2])

plt.figtext(.5, 0.46, "Using custom cut map and FixedPointNormalize (adding hard edge between land and sea)", ha="center", size=14)

norm4 = FixPointNormalize(sealevel=0, vmax=3400)

im4 = ax[1,0].imshow(data+1000, norm=norm4, cmap=cut_terrain_map)

fig.colorbar(im4, ax=ax[1,0])

norm5 = FixPointNormalize(sealevel=0, vmax=3400)

im5 = ax[1,1].imshow(data, norm=norm5, cmap=cut_terrain_map)

cbar = fig.colorbar(im5, ax=ax[1,1])

norm6 = FixPointNormalize(sealevel=0, vmax=0)

im6 = ax[1,2].imshow(data-2400.1, norm=norm6, cmap=cut_terrain_map)

fig.colorbar(im6, ax=ax[1,2])

for i, name in enumerate(["land only", "coast line", "sea only"]):

for j in range(2):

ax[j,i].text(0.96,0.96,name, ha="right", va="top", transform=ax[j,i].transAxes, color="w" )

plt.show()

matlab中elevation函数功能,Matlab的Demcmap的Python等价物(elevation+/appropriate colormap)...相关推荐

  1. matlab中axis函数程序,matlab中axis函数

    % 计算函数值,zz 也是21x21的矩阵 为了方便测试立体绘图,MATLAB 提供了一个 peaks...meshz 可将曲面加上围裙: [x,y,z]=peaks; meshz(x,y,z); a ...

  2. matlab中randint函数用法,matlab中rand randn randint函数的区别

    matlab中rand函数是产生0到1的随机分布 matlab中randn函数是产生标准正态分布 randint是产生整数随机数,默认为0和1 %%%%%%%%%%%rand%%%%%%%%%%%%% ...

  3. matlab中imadjust函数,浅析matlab中imadjust函数

    imadjust imadjust是一个计算机函数,该函数用于调节灰度图像的亮度或彩色图像的颜色矩阵.在matlab的命令窗口中键入: doc imadjust或者help imadjust即可获得该 ...

  4. matlab中udt函数,《MATLAB信号处理超级学习手册》——2.5 离散时间信号中的运算...

    本节书摘来自异步社区<MATLAB信号处理超级学习手册>一书中的第2章,第2.5节,作者:MATLAB技术联盟 , 史洁玉著,更多章节内容可以访问云栖社区"异步社区"公 ...

  5. matlab中fval函数,请问matlab中[x,fval,exitflag,output] = simulannealbnd(fun,...)函数怎么调用...

    请问matlab中[x,fval,exitflag,output] = simulannealbnd(fun,...)函数怎么调用,有相应的实例吗?或者帮我看一下下面的程序,怎么改. function ...

  6. matlab中clear的功能,matlab中clc,close,close all,clear,clear all作用区别

    学习链接 clc:清除命令窗口的内容,对工作环境中的全部变量无任何影响 close:关闭当前的Figure窗口 close all:关闭所有的Figure窗口 clear:清除工作空间的所有变量 cl ...

  7. matlab中 trapz函数,trapz(matlab中trapz函数用法)

    采用梯形法求积分 下面两种用法等效 h=pi/200; t=0:h:pi/2; y=sin(t)+cos(2*t); z1=trapz(t,y) z2=trapz(y)*h z1 = 1.0000 z ...

  8. matlab中normcdf函数用法,MATLAB NORMCDF

    MATLAB 中关于常见的概率分布密度函数的语句及格 式 MATLAB 中关于常见的概率分布密度函数的语句及格式 normpdf(x,mu,sigma) 正态分布密度函数. uifpdf(x,a,b) ...

  9. matlab中liccode函数,基于matlab车牌识别系统设计与实现(最终版)

    <基于matlab车牌识别系统设计与实现.doc>由会员分享,可在线阅读全文,更多相关<基于matlab车牌识别系统设计与实现(最终版)>请在www.woc88.com上搜索. ...

最新文章

  1. 数据科学家线性规划入门指南
  2. .NET : VS 2008中的一个转换器
  3. Travis CI mysql_DevOps工具介绍连载(34)——Travis CI
  4. 自学linux指令分析-find
  5. UVA - 817According to Bartjens
  6. JQuery中trim函数的具体实现代码
  7. 谈谈我的session跨域处理方法
  8. DevExpress Dashboard for .NET简化商业智能开发
  9. java之pdf打印
  10. jQuery EasyUI快速入门01
  11. linux系统可以用autocad吗,还在找适用于Linux系统的CAD软件?这5款千万别错过!
  12. background系列属性
  13. c++课程设计图书馆管理系统总结
  14. java 统一日志_基于log4j实现统一日志管理
  15. STM32L475 SPI驱动LCD ST7789V2详解
  16. 关于CASIO系列可编程计算器在公路施工测量中的应用
  17. 服务器dump文件位置,为服务器核心安装配置内存转储文件
  18. 5G移动通信标准学习笔记(一)
  19. 2020春季学期哈工大软件构造学习心得三
  20. 一篇文章教你如何写出【✨无法维护✨】的代码?

热门文章

  1. 《UnityAPI.Network网络》(Yanlz+Unity+SteamVR+云技术+5G+AI+VR云游戏+Network+isClient+Connect+Server+立钻哥哥++OK++)
  2. 网络营销实战课-微信实操
  3. 武汉理工大学数学建模大作业
  4. Python内存驻留机制
  5. 世界睁大眼睛关注中国春节
  6. easypoi 语法_语法微课初中英语语法复习大全
  7. 对不起,我不是一个善良的人
  8. A Cross-Modal Image and Text Retrieval Method Based on Efficient Feature Extraction and Interactive
  9. 如何上好大学计算机基础,如何学好大学计算机基础
  10. Python变量,常量,基础数据类型,input用户交互