Я пытаюсь сгенерировать pcolormesh
, где градиент цвета будет меняться в зависимости от нелинейной периодической функции, такой как abs
от cos.Пользовательской нормализации должно быть достаточно.До сих пор я пробовал код, приведенный ниже:
class XNormalize(mcolors.Normalize):
def __call__(self, value, clip=None):
return np.ma.masked_array(np.abs(np.cos(value)))
Я не уверен, что в этом случае применим отображение self.vmin
, self.vmax
, поскольку cos
может фактически принимать любой ввод.
Код для генерации вывода:
inner_azimuths = np.arange(0, 361, 1)
inner_zeniths = np.arange(50, 55, 1)
inner_values = inner_azimuths * np.ones((5, 361))
fig = plt.figure(tight_layout=True)
ax = fig.add_subplot(111, polar=True)
ax.pcolormesh((inner_azimuths)*np.pi/180.0, inner_zeniths, inner_values, cmap='jet_r', zorder=2, antialiased=True, norm=XNormalize(vmin=0, vmax=2*np.pi))
Вывод в настоящее время выглядит следующим образом:

Я также попробовал следующую функцию:
def distortColorMap(cm,inv = lambda x:x):
"""Inspired from 'make_colormap' in Serenity's answer.
Inputs : a pre-existing colormap cm,
the distorsion function inv
Output : the distorted colormap"""
def f(color,inv):
"""In the sequence definition, modifies the position of stops tup[0] according the transformation function.
Returns the distorted sequence."""
return map(lambda tup:(inv(tup[0]),tup[1],tup[2]),color)
# Extract sequences from cm, apply inv
C = cm.__dict__['_segmentdata']
cdict = {'red': f(C['red'] ,inv), 'green': f(C['green'],inv), 'blue': f(C['blue'] ,inv)}
name = 'new_'+cm.__dict__['name']
return colors.LinearSegmentedColormap(name, cdict)
Бит это тоже не сработало.
Источники: (a) , (b)