If you want to create a color ramp you can do the following. Using https://matplotlib.org/3.2.1/tutorials/colors/colormap-manipulation.html as a reference:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
def plot_examples(colormaps):
"""
Helper function to plot data with associated colormap.
"""
np.random.seed(19680801)
data = np.random.randn(30, 30)
n = len(colormaps)
fig, axs = plt.subplots(1, n, figsize=(n * 2 + 2, 3),
constrained_layout=True, squeeze=False)
for [ax, cmap] in zip(axs.flat, colormaps):
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
fig.colorbar(psm, ax=ax)
plt.show()
colors = ["purple", "red"]
cmap1 = LinearSegmentedColormap.from_list("mycmap", colors)
plot_examples([cmap1])

You can also use the colormap to get values for a normal plot:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
# Creating the colar map
colors = ["purple", "red"]
cmap1 = LinearSegmentedColormap.from_list("mycmap", colors)
# Data used in plot
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
plt.plot(t, s, color=cmap1(0.1))
plt.show()
Here you can change the 0.1
in the second to last line to choose where on the colormap you want to query (0-255).
