0

I have a list of chars that I plot as title with its corresponding x coordinates using matplotlib's text. I have a string that will exist as a pattern within the plotted text. How do I bolden and underline the string once found in the title. Here is what I have so far.

import matplotlib.pyplot as plt

st = ['D', 'K', 'J', 'K', 'D', 'J', 'K', 'D', 'K', 'D', 'D', 'T', 'T', 'D']
word = 'KDDT'
fig, ax = plt.subplots()
st1 = [x for x, y in enumerate(st)]
ax.set_xticks(st1)
loc = 1.2
arg = dict(fontsize=10, va='top')

for x, y in enumerate(st): 
    ax.text(x, loc, y, **arg )
plt.plot(range(14), range(14))   
plt.show 

I get the title on top but I am not sure how to proceed with the bold and underline of the word KDDT within the title on the plot. The word can occur anywhere within the st list.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Starter
  • 417
  • 4
  • 12
  • [Here](https://stackoverflow.com/questions/34937048/make-part-of-a-matplotlib-title-bold-and-a-different-color) is how to make part of a title bold. I'm not sure if one can underline text with matplotlib's text. But you can [use latex](https://stackoverflow.com/questions/10727368/underlining-text-in-python-matplotlib) for it. – ImportanceOfBeingErnest Jun 30 '19 at 20:35
  • I saw that answer of yours earlier but it is different from what I need. The title is a plot on its own with its own coordinates and I will need to compare the word with contents of the title then bold and underline once found – Starter Jun 30 '19 at 20:40
  • So in that answer it is shown how to make some text bold. I strongly doubt you can underline text easily, [this](https://stackoverflow.com/questions/41642265/how-to-put-underbar-below-a-letter-underscored-characters-in-matplotlib) would be another workaround. So in total I would opt for not underlining anything, because that just is too hard. – ImportanceOfBeingErnest Jun 30 '19 at 20:43
  • I guess this will be tough to do then. Hopefully, I can find a way around it – Starter Jun 30 '19 at 20:47

0 Answers0