0

I can make italic text like this:

plt.title('$\it{Text}$')
plt.show()

I'd like to have some italic text (but not all) and use the .format() function, e.g.:

plt.title('$\it{Text}$ = {}'.format(func))
plt.show()

This returns KeyError: 'Text'

2 Answers 2

1

Since matplotlib.pyplot.title accepts style as a keyword argument, you can pass italic :

import matplotlib.pyplot as plt

text = "Stack Overflow"

plt.title(f"{text}", style= "italic")
#or plt.title("{}".format(text), style= "italic")

plt.show()

enter image description here

Or if only some of the desired text is to be italic:

text = "italic" 
text2 = "something" 

plt.title(f"$\it{text}$ ~ {text2}")
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry if my question was unclear. Italic text is working without issue. I'd like to have some italic text and use the .format() function in the same string.
Well, that's what I did in my answer, isn't it ?
0

I Hope I understood your question.

you can check this web if you wanna know more about format function: https://www.geeksforgeeks.org/python-string-format-method/

import matplotlib.pyplot as plt

s=[11,22,33,44,55,66]
a=[22,33,44,22,1,34]

plt.plot(a,s)
plt.title("{}".format("GLITCH"),style="italic")
plt.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.