I have seen numerous resources for establishing unique cmap color codes, such as:
i) Merge colormaps in matplotlib
ii) Python: Invalid RGBA argument 0.0 color points according to class
iii) Defining a discrete colormap for imshow in matplotlib
None of these quite answer my question. I have 900 rows and each row has 200 data points that are either 1 or 0. In the finished product, the top 20% of the chart should have blue spikes for 1's and the bottom 80% should have red spikes for 1's. So y-axis >=720== blue and y-axis <720 = red.
The imshow cmap codes for these colors are plt.cm.Blues and plt.cm.Red
It's relatively easy to have all the spikes be coded blue:
img0 = raster[0].imshow(spikes, cmap=plt.cm.Blues, origin='lower', aspect="auto")
However, when I try to split the coding of cmap, I run into RGB errors related to the format of the input data. My code is below, and any help would be appreciated.
colors1 = plt.cm.Reds(np.linspace(0,1,int(200*900*.8)).reshape(int(900*.8),200))
colors2 = plt.cm.Blues(np.linspace(0,1,int(200*900*.2)).reshape(int(900*.2),200))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list('mycmap', np.append(colors1,colors2))
img0 = raster[0].imshow(spikes, cmap=cmap, origin='lower', aspect="auto")
Final answer that works
img0 = raster[0].imshow(spikes[720:,:], cmap='Blues', extent=[0, 30, 720, 899], origin='lower', aspect="auto")
img0 = raster[0].imshow(spikes[:720,:], cmap='Reds', extent=[0, 30, 0, 719], origin='lower', aspect="auto")
raster[0].set_ylim(0, 900)