How to modify ax.set_title to include differents colors?

99 views Asked by At

I am plotting a specific figure using the following program:

alpha, beta = 0.5, 0.5
fig, ax = plt.subplots(1, 1, figsize = (6,3))
ax.set_title(r"Predicted $x$ with Bayes Factor w.r.t. $\beta(1,1)$:" + "\n" 
             + "> 3 (green) or < 3 (blue)" + "\n" 
             + r"when prior = $\beta$" + f"({alpha}, {beta}) " 
             + f"[n = {n}] " + "-NO DATA-", 
             fontsize = '15')
plt.show()

Is there a way to modify the instructions given to ax.set_title in order to have the text >3 (green) displayed in green color and the text >3 (blue) displayed in blue color, inside the whole title?

I tried to play with r"\textcolor{green}{> 3 (green)}" (as an example) but that turned out to be useless...

Should I need to split the title in several parts with different specifications in each part? But how to do that, if it is the case?

Or is there a nice pythonic way to do the job?

Any advice highly appreciated.

0

There are 0 answers