当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Matplotlib.colors.PowerNorm用法及代码示例


Matplotlib是Python中令人惊叹的可视化库,用于数组的二维图。 Matplotlib是一个基于NumPy数组的多平台数据可视化库,旨在与更广泛的SciPy堆栈配合使用。

matplotlib.colors.PowerNor

matplotlib.colors.PowerNorm类属于matplotlib.colors模块。 matplotlib.colors模块用于将颜色或数字参数转换为RGBA或RGB。此模块用于将数字映射到颜色或以一维颜色数组(也称为colormap)进行颜色规格转换。

matplotlib.colors.PowerNorm类用于将值线性映射到-的范围,然后在该范围内应用power-law归一化。它的基类是matplotlib.colors.Normalize。

该类的方法:

  • 逆(自我,价值):此方法返回颜色图的反转值。

范例1:



import matplotlib.pyplot as plt 
import matplotlib.colors as mcolors 
import numpy as np 
from numpy.random import multivariate_normal 
  
# data for reproducibality 
data = np.vstack([ 
    multivariate_normal([10, 10],  
                        [[3, 2],  
                         [2, 3]], 
                        size = 100000), 
      
    multivariate_normal([30, 20],  
                        [[2, 3],  
                         [1, 3]],  
                        size = 1000) 
]) 
  
gammas_array = [0.9, 0.6, 0.4] 
  
figure, axs = plt.subplots(nrows = 2, 
                           ncols = 2) 
  
axs[0, 0].set_title('Linear normalization') 
axs[0, 0].hist2d(data[:, 0], 
                 data[:, 1],  
                 bins = 100) 
  
for ax, gamma in zip(axs.flat[1:], 
                     gammas_array):
      
    ax.set_title(r'Power law $(\gamma =% 1.1f)$' % gamma) 
    ax.hist2d(data[:, 0],  
              data[:, 1], 
              bins = 100,  
              norm = mcolors.PowerNorm(gamma)) 
  
figure.tight_layout() 
  
plt.show()


输出:

matplotlib.colors.PowerNorm

范例2:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.colors as colors 
  
max_N = 100
A, B = np.mgrid[-3:3:complex(0, max_N), 
                -2:2:complex(0, max_N)] 
  
  
# PowerNorm:using power-law  
# trend in X  
A, B = np.mgrid[0:3:complex(0, max_N),  
                0:2:complex(0, max_N)] 
  
X1 = (1 + np.sin(B * 10.)) * A**(2.) 
  
figure, axes = plt.subplots(2, 1) 
  
pcm = axes[0].pcolormesh(A, B, X1, 
                         norm = colors.PowerNorm(gamma = 1./2.), 
                         cmap ='PuBu_r') 
  
figure.colorbar(pcm, ax = axes[0], 
                extend ='max') 
  
pcm = axes[1].pcolormesh(A, B, X1, 
                         cmap ='PuBu_r') 
  
figure.colorbar(pcm, ax = axes[1],  
                extend ='max') 
  
plt.show()

输出:
matplotlib.colors.PowerNorm




相关用法


注:本文由纯净天空筛选整理自RajuKumar19大神的英文原创作品 Matplotlib.colors.PowerNorm class in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。