Matplotlib Flashcards
How do you plot a numpy list?
import matplotlib.pyplot as plt
plt. plot(list_name, norm.pdf(list_name))
plt. show()
How do you plot multiple lists?
Use the plt.plot list as many times as necessary.
How do you save the current plot to a file?
plt.savefig(‘file_destination.png’, format=’png’)
How do you limit the axes to a certain range of numbers?
axes = plt.axes()
axes. set_xlim([-5,5])
axes. set_ylim([0,1.0])
How do you set the locations of the tick marks along the axes?
axes = plt.axes()
axes. set_xticks(list_of_xticks)
axes. set_yticks(list_of_yticks)
How do you add a grid to the graph?
axes.grid()
How do you write the extra pyplot.plot parameter controlling color and style?
‘r:’
First letter of the color, followed by a specific symbol.
What are the colors that can be represented with plotted lines?
red, green, blue, cyan, magenta, yellow, black, white
What are the styles that can be represented with plotted lines?
'-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style '.' point marker ',' pixel marker 'o' circle marker 'v' triangle_down marker '^' triangle_up marker '' triangle_right marker '1' tri_down marker '2' tri_up marker '3' tri_left marker '4' tri_right marker 's' square marker 'p' pentagon marker '*' star marker 'h' hexagon1 marker 'H' hexagon2 marker '+' plus marker 'x' x marker 'D' diamond marker 'd' thin_diamond marker '|' vline marker '_' hline marker
How do you label axes?
plt. xlabel(‘—’)
plt. ylabel(‘—’)
How do you make a legend?
plt.legend([‘Title1’, ‘Title2’], loc=4)
The integer loc controls where the legend is.
How do you make a pie chart?
plt.pie(values, colors= colors, labels=labels, explode = explode)
What do the parameters for the pie chart represent?
Values: a list of integers representing percents of each slice (20 corresponds to a twenty-percent slice)
Colors: a list of characters corresponding to the RGB primary and secondary colors, plus black and white
Labels: a list of strings corresponding to the labels for each slice
Explode: a list of floats corresponding to how far removed the slice is from the center (0.0 means no explosion)
How do you give a plot a title?
plt.title(“Plot name”)
How do you make a bar chart?
plt.bar(range(0,5), values, color= colors)