<s>[INST] I have the following python code:

```python
plt.imshow(x_train[0], cmap='gray', interpolation = 'nearest')
```

I'm looking for a colormap that interpolates from blue through white to red. How do i do that? [/INST] Some colormap presets that interpolate from blue through white to red in matplotlib are the ```bwr``` and ```coolwarm``` diverging colormaps.

```
import numpy as np
import matplotlib.pyplot as plt

gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))

plt.imshow(gradient, aspect='auto', cmap='bwr')
```</s>\ <s>[INST] How would I make my own colormap instead of relying on a preset? [/INST] To make your own colormap you can use matplotlib `LinearSegmentedColormap`. In the below code I show you how to use it and how to enter colors in a few different formats.

```py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import matplotlib.colors as mcolors

# I'll show you multiple ways to enter colors
blue = (0, 0, 1, 1)  # you can use a rgba tuple
white = mcolors.to_hex('white') # a name or a hex string, here we are converting from a name to a hex string
cmap = LinearSegmentedColormap.from_list("mycmap", [blue, white, 'red'])

gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))

# now you pass in your colormap object into the cmap argument in pyplot plotting methods
plt.imshow(gradient, aspect='auto', cmap=cmap)
```</s>