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
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f5f930f00eac> in <module>
---> 10 axs[0].title("My title")
TypeError: 'Text' object is not callable
Solution:
Use .set_title("My title")
instead of .title("My title")
!
While
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()
!
from matplotlib import pyplot as plt
fig, axs = plt.subplots(2, 1)
# ...
axs[0].set_title("My title")