Compound DualCmapΒΆ

../../_images/plaid_dualcmap.png

Similar to the Compound Color Maps example, a dual colormap is applied to map colors using the map_color_from_op method.

import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

#.. Plaid Dualcmap

# 1. Define function to examine .....................................

def flatten(rtp,twists) :
    r,t,p = rtp
    flat = 0.7
    T = t - twists*( p )
    R = (1-flat)*r + flat*(np.sin(p))**4
    return R,T,p

# 2. Setup and map surfaces .........................................

cmap = cmu.binary_cmap('tab:red','mistyrose')
cmap = cmu.mirrored_cmap(cmap)
cmap = cmu.mirrored_cmap(cmap)
cmap = cmu.mirrored_cmap(cmap)
cmap = cmu.mirrored_cmap(cmap)
cmap = cmu.mirrored_cmap(cmap,name='striped')
cmap2d = cmu.DualCmap(cmap,cmap,kind='ave')

surface = s3d.SphericalSurface.grid(270,32*4,'r')
surface.map_color_from_op( lambda rtp : cmap2d(rtp[1],rtp[2]) )
surface.map_geom_from_op(  lambda rtp : flatten(rtp,1) )
                                      
N = 200
x=np.linspace(0,1,N)
y=np.linspace(0,1,N)
z = cmap2d(*np.meshgrid(x, y)).T

# 3. Construct figures, add surface, plot ...........................
info = str(surface) +'\n' + str(cmap2d)
minmax = (-0.5*N,1.5*N)
fig = plt.figure(figsize=(8,4))
fig.text(0.975,0.975,info, ha='right', va='top', fontsize='smaller', multialignment='right')

ax1 = fig.add_subplot(121, projection='3d', aspect='equal')
fig.text(0.45,0.85,'Plaid DualCmap', ha='left', 
    va='top', fontsize='xx-large', multialignment='right')
ax1.set_axis_off()
s3d.auto_scale(ax1,surface,uscale=0.65)
ax1.add_collection3d(surface.shade(0.5,[1,1,1]).hilite())

ax2 = fig.add_subplot(122)
fig.text(0.75,0.23,r'$\theta$  cmap axis', ha='center', va='center', fontsize='large')
fig.text(0.61,0.51,r'$\varphi$ cmap axis', ha='center', va='center', fontsize='large', rotation=90)
ax2.set(xlim=minmax, ylim=minmax )
ax2.set_axis_off()
ax2.imshow(z)

fig.tight_layout()
plt.show()