归一化颜色图的数据

如何解决归一化颜色图的数据

我正在绘制带有2个数组数据的大熊猫形状的颜色:

这是我的第一个数组。

     newI = 
    array([ -467,-415,-414,-1001,-246,-147,-523,-327,-583,-541,-290,-453,-505,-791,-812,-672,-558,-559,-1055,-703,-419,-499,-273,-574,-802,-450,-743,-221,-1282,-704,-352,-734,-430,-353,-515,-1121,-664,-586,-171,-881,-402,-1024,-543,-527,-384,-775,-931,-1380,-1662,-1069,-952,-435,-1051,-921,-1211,-794,-547,-313,-511,-993,-262,-255,-675,-793,-1053,-702,-967,-1016,-230,-405,-869,-689,-935,-190,-1473,-883,-1233,-240,-607,-339,-1130,-909,-836,-667,-457,-847,-538,-606,-800,-322,-1339,-691,-627,-365,-600,-289,-810,-577,-187,-375,-426,-662,-695,-1003,-40,-1012,-279,-966,-587,-641,-753,-461,-563,-604,-1013,-625,-506,-416,-1385,-459,-760,-347,-308,-555,-325,-1588,-566,-533,-843,-501,-448,-1022,-654,-602,-1201,-814,-754,-361,-1141,-725,-256,-601,-379,-496,-1099,-1101,-598,-442,-773,-295,-1292,-1234,-868,-1135,-251,-1398,-1306,-693,-560,-512,-1168,-482,-431,-1199,-1249,-413,-1018,-194,-932,-1028,-436,-955,-463,-1303,-676,-554,-875,-661,-443,-89,-879,-475,-660,-684,-174,-902,-1241,-1320,-575,-855,-222,-890,-701,-1082,-531,-1008,-1357,-433,-192,-343,-477,-938,-798,-259,-398,-778,-484,-817,-564,-536,-1599,-968,-845,-1592,-1139,-229,-926,-474,-392,-990,-465,-497,-395,-468,-310,-507,-1205,-705,-739,-609,-809,-610,-421,-1057,-2023,-1105,-618,-466,-1291,-616,-620,-571,-904,-383,-544,-688,-769,-852,-298,-782,-758,-371,-813,-594,-284,-215,-452,-936,-994,-981,-502,-510,-671,-721,-829,-288,-653,-493,-983,-722])

这是我的第二个数组:

    array([-2407,-1992,-3400,-4826,-1544,-820,-3120,-1469,-2869,-3622,-1738,-2122,-2773,-2939,-3558,-3575,-3082,-2494,-3591,-5022,-1619,-2608,-3371,-3054,-1596,-2538,-3566,-2035,-3490,-522,-5362,-3055,-1517,-4107,-2039,-2497,-2302,-5513,-3876,-4303,-831,-4457,-2027,-5083,-2716,-2284,-1288,-3781,-4707,-6903,-8592,-5763,-4644,-1999,-4894,-3190,-6263,-3484,-3090,-1899,-2640,-3940,-2919,-629,-2018,-4228,-4075,-5249,-2794,-4061,-4089,-1500,-2434,-3867,-3359,-4070,-1472,-7334,-4367,-5422,-1563,-3092,-1803,-4664,-4096,-3875,-3061,-1181,-4098,-2850,-4356,-2239,-3102,-1498,-6458,-3495,-2863,-3568,-1752,-3422,-1768,-3675,-2061,-919,-1452,-2512,-1924,-3668,-3931,-4348,-6232,-1065,-4261,-2739,-3392,-3962,-2369,-2508,-3156,-4759,-3012,-3345,-2566,-7910,-2215,-3581,-2155,-2643,-1420,-7449,-3023,-2982,-4913,-2835,-1748,-4679,-2950,-2951,-5515,-4195,-1746,-1437,-5429,-3246,-1556,-2635,-1534,-3553,-4451,-5655,-2616,-2724,-4445,-1642,-6640,-5211,-5014,-4909,-1103,-5658,-2096,-2427,-5719,-3152,-2717,-2544,-4226,-4813,-2319,-2261,-4844,-5383,-5057,-2981,-5448,-1526,-1749,-3550,-3736,-1893,-5812,-2686,-5923,-3145,-3569,-2523,-4586,-2931,-4104,-2301,-666,-4402,-3201,-3171,-2598,-4279,-3765,-3024,-3085,-3732,-5899,-6464,-3993,-4583,-1126,-4193,-4214,-3902,-2132,-3712,-4879,-6907,-1524,-1987,-1444,-2086,-3229,-1316,-4331,-3150,-4449,-1700,-1486,-3650,-2478,-4166,-2618,-3308,-2458,-7441,-4452,-2438,-4722,-6949,-1712,-4727,-792,-1610,-1951,-3965,-1410,-2958,-2167,-2050,-2152,-2236,-3235,-5999,-4024,-3111,-3196,-3881,-2647,-2579,-6387,-9912,-4677,-2983,-1913,-7547,-3166,-2990,-2183,-3401,-2080,-3056,-2225,-2546,-4421,-2975,-1552,-2090,-3871,-2032,-3564,-3273,-1579,-4338,-1371,-3600,-1253,-2083,-1439,-2281,-2045,-4406,-4380,-4129,-2520,-2529,-2108,-3081,-3561,-2601,-3069,-1852,-5888,-5730,-3386])

绘制这些数组数据的代码如下所示。

    area_gpd = gpd.read_file("....shp")
    area_gpd['population'] = newI

    plt.rcParams.update({'font.size':32})
    west,south,east,north = area.unary_union.bounds

    fig,ax = plt.subplots(figsize=(40,40))
    cmap = LinearSegmentedColormap.from_list('mycmap',[ 'green','white'])

    melbourne_gpd.plot(ax=ax,column='population',legend=False,cmap=cmap,zorder=3)
    sm = plt.cm.ScalarMappable(cmap=cmap,\
                          norm=plt.Normalize(vmin=-9912,vmax=-284))

它可以使事物正常化,因此强度现在有所不同。 有什么功能可以标准化此数据? 我希望对于较大的值,地图会更暗。谁能给我一些建议?

非常感谢

解决方法

我从一个关于stackoverflow的人那里找到了一个很好的解决方案:

import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt


class MidpointNormalize(mpl.colors.Normalize):
    def __init__(self,vmin,vmax,midpoint=0,clip=False):
        self.midpoint = midpoint
        mpl.colors.Normalize.__init__(self,clip)

    def __call__(self,value,clip=None):
        normalized_min = max(0,1 / 2 * (1 - abs((self.midpoint - self.vmin) / (self.midpoint - self.vmax))))
        normalized_max = min(1,1 / 2 * (1 + abs((self.vmax - self.midpoint) / (self.midpoint - self.vmin))))
        normalized_mid = 0.5
        x,y = [self.vmin,self.midpoint,self.vmax],[normalized_min,normalized_mid,normalized_max]
        return sp.ma.masked_array(sp.interp(value,x,y))


vals = sp.array([[-5.,0],[5,10]]) 
vmin = -1225
vmax = 669

norm = MidpointNormalize(vmin=vmin,vmax=vmax,midpoint=0)

它将很好地完成您的色图工作。 这是我找到解决方案的地方的链接:Colorplot that distinguishes between positive and negative values

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-