Is there a way to add title (and xlabel and ylabel) to plt.scatter(x,y,...) or plt.plot(x,y,...) directly without writing additional lines?
It is easy to add it when we use Series_name.plot in which we simply write Series_name.plot(...,title='name') but it does not work for me if I write: plt.scatter(...,title='name') or plt.plot(...,title='name')
[plt<< import matplotlib.pyplot as plt]
I am using Python 3.
From the documentation of plt.scatter()
there is no such arguments to set the title or labels.
But neither does the plt.plot()
command have such arguments. plt.plot(x,y, title="title")
throws an error AttributeError: Unknown property title
. So I wonder why this should work in either case.
In any case, the usual way to set the title is plt.title
. The usual way to set the labels is plt.xlabel
and plt.ylabel
.
import matplotlib.pyplot as plt x= [8,3,5]; y = [3,4,5] plt.scatter(x,y) plt.title("title") plt.xlabel("x-label") plt.ylabel("y-label") plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With