Matplotlib string with italics and using .format()
Question:
I can make italic text like this:
plt.title('$it{Text}$')
plt.show()
I’d like to have italic text and use the .format() function, e.g.:
plt.title('$it{Text}$ = {}'.format(func))
plt.show()
This returns KeyError: 'Text'
Answers:
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()
Or if only some of the desired text is to be italic:
text = "italic"
text2 = "something"
plt.title(f"$it{text}$ ~ {text2}")
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()
I can make italic text like this:
plt.title('$it{Text}$')
plt.show()
I’d like to have italic text and use the .format() function, e.g.:
plt.title('$it{Text}$ = {}'.format(func))
plt.show()
This returns KeyError: 'Text'
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()
Or if only some of the desired text is to be italic:
text = "italic"
text2 = "something"
plt.title(f"$it{text}$ ~ {text2}")
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()