Unable to render different colors for specific characters within a LaTeX string

I would like to change the color of a substring within a LaTeX string for a MatPlotLib plot title. The code below gives no errors or warning; but, does not render the color specified.

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('text.latex', preamble = r'\usepackage{xcolor}')

N = 50
x = np.random.rand(N)
y = np.random.rand(N)

fig, ax = plt.subplots()
ax.scatter(x, np.cos(x), color = 'blue', marker = "+", s=47.5)
#ax.set_title(r"\textcolor{red}{X} $\color{red}{X}$") # does not work either


How can I render the first X with the color red?


N?r du har kontakt med oss p? Uppsala universitet med e-post s? inneb?r det att vi behandlar dina personuppgifter. F?r att l?sa mer om hur vi g?r det kan du l?sa h?r: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190204/d323e761/attachment.html>