Python Part 5: Matplotlib Flashcards
import matplotlib
import matplotlib.pyplot as plt
Plot a diagram showing points from two arrays, x and y, drawn with a red line and showing the datapoints, with a label.
plt.plot(x,y, ‘ro-‘, label = ‘Stevie’)
add a legend
plt.legend()
add a legend in the upper left of a diagram
plt.legend(loc = ‘upper left’ )
add a title, first plot, with the font size 40
plt.title(‘first plot’,fontsize=40)
add labels for the x and y axes
plt.xlabel(‘x axis’,fontsize=18)
plt.ylabel(‘y axis’)
plot a histogram
plt.hist(data,30,color=’r’,density=True)
plot a pie chart
plt.pie(y,labels=dataLabels)
Plot a scatterplot
x=np.arange(100)
y=4.0-0.02*x+np.random.normal(size=100)
plt.scatter(x,y)
plt.show()