Mã python sau tạo một bản đồ nhiệt của một ma trận có chứa các giá trị phân phối chuẩnrộng phi tuyến tính của một bản đồ màu để tăng cường độ tương phản
import numpy as np
from matplotlib import pylab as plt
np.random.seed(123) #make sure we all have same data
m = np.random.randn(200).reshape(10, 20)
plt.imshow(m, cmap='RdYlGn', interpolation='nearest')
plt.colorbar()
Đây là sản phẩm của mã này
Tôi muốn nâng cao độ tương phản của hình ảnh này bằng cách "mờ dần" các giá trị gần bằng không. Tôi có thể dễ dàng thực hiện việc này bằng cách sử dụng chia tỷ lệ disigmoid của dữ liệu gốc như sau:
def disigmoidScaling(values, steepnessFactor=1, ref=None):
''' Sigmoid scaling in which values around a reference point are flattened
arround a reference point
Scaled value y is calculated as
y = sign(v - d)(1 - exp(-((x - d)/s)**2)))
where v is the original value, d is the referenc point and s is the
steepness factor
'''
if ref is None:
mn = np.min(values)
mx = np.max(values)
ref = mn + (mx - mn)/2.0
sgn = np.sign(values - ref)
term1 = ((values - ref)/steepnessFactor) ** 2
term2 = np.exp(- term1)
term3 = 1.0 - term2
return sgn * term3
plt.imshow(disigmoidScaling(m, 4), cmap='RdYlGn', interpolation='nearest')
plt.colorbar()
Đây là đầu ra.
Tôi hài lòng với kết quả, ngoại trừ một thực tế rằng trong phiên bản này giá trị ban đầu đã được trao đổi cho những người thu nhỏ lại.
Có cách nào để thực hiện ánh xạ các giá trị phi tuyến tính để cố định không?
Câu hỏi này cũng có thể được quan tâm ở đây: https://stackoverflow.com/questions/46038206/arbirtrary-non-linear-colorbar-using-matplotlib – ImportanceOfBeingErnest