Q:

How to plot a line that is partially colorized?

As shown in the figure,
How can I plot a line that have different colors based on a specific value of x ?

A:

The simplest solution here may be to slice your data at the corresponding index of x_lim found by np.where :
from matplotlib import pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,100)
y = np.cos(x)*np.exp(-x/2)

# specify your x limitation
x_lim = np.pi
# find the first corresponding idx where the condition x>=x_lim hold
x_lim_idx = np.where(x>=x_lim)[0][0]

# plot sliced data
plt.plot(x[:x_lim_idx],y[:x_lim_idx],'r')
plt.plot(x[x_lim_idx:],y[x_lim_idx:],'b')

which gives for x_lim = np.pi :

And if the remaining gap between the lines bothers you, for small x discretization for instance, you can still close it by making the two slices overlap.

