How to fix matplotlib .title() TypeError: 'Text' object is not callable
Problem:
You want to set the title of a matplotlib plot using .title("My title") but you see an error messsage like
matplotlib_title_trace.txt
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f5f930f00eac> in <module>
---> 10 axs[0].title("My title")
TypeError: 'Text' object is not callableSolution
Use .set_title("My title") instead of .title("My title") !
While
matplotlib_title_set_example.py
from matplotlib import pyplot as plt
plt.title("My title")works fine, if you have an axes object like the one you get from plt.subplots(), you’ll have to use set_title()!
matplotlib_title_axes_example.py
from matplotlib import pyplot as plt
fig, axs = plt.subplots(2, 1)
# ...
axs[0].set_title("My title")Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow