Actually I want to give title to my line plot of matplotlib.pyplot line plot, but I am facing this error
"TypeError: 'str' object is not callable while giving title to the matplotlib.pyplot of line line plot"
Here is my code.
` import numpy as np import pandas as pd from matplotlib import pyplot as plt from pydataset import data
austres = data('austres') austres.head()
plt.figure(figsize=(10,4)) # plot_size
plt.plot(austres['time'], austres['austres'], 'v-g')
plt.title(label="Population Graph")enter code here
plt.xlabel('Time')
plt.ylabel('Population')
`
CodePudding user response:
Probable reason is you assigned to plt.title
before. Someting like
plt.title = "Population Graph"
But what it does is to change the plt.title
function of matplotlib to now refer to a string! Language is flexible so you can do this and results in error after you try call it. It tries like "Population Graph"()
.
To solve it:
either detect that
plt.title = ...
code and erase it and re-run the scriptif this is a jupyter like enivornment (e.g. notebook), detect that line and delete it if not already and then restart the kernel and re run again.
CodePudding user response:
Try to use this instead
plt.title('Your Title')