Matplotlib 2.x By Example
上QQ阅读APP看书,第一时间看更新

Plotting a curve

Plotting a line graph of the list can be as simple as:

plt.plot(evens)

When only one parameter is specified, Pyplot assumes the data we input is on the y axis and chooses a scale for the x axis automatically.

To plot a graph, call plt.plot(x,y) where x and y are the x coordinates and y coordinates of data points:

plt.plot(evens,evens**2)

To label the curve with a legend, we add the label information in the plot function:

plt.plot(evens,evens**2,label = 'x^2')
plt.legend()