Q. Following code is plotting the desired graph but legends are not showing despite giving the legend() of PyPlot. What could be the reason? Suggest a solution for the problem.
plt.plot(x, y)
plt.plot(x, z)
plt.legend (loc = "upper left")
Answer :-
The above code won't print the legends because with the plot(), the labels are missing. The legend() will work only when we specify label for data series being plotted in the plot().
The solution for above problem will be:-
plt.plot(x, y, label = "Y data")
plt.plot(x, z, label = "Z data")
plt.legend (loc = "upper left")
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )