Python Plotting Guide (Notes from C. Lochhaas, 8/13) Make sure to: import matplotlib.pyplot as plt To plot y vs x: plt.plot(x,y) To change line style: Include a linestyle marker in call to plot, e.g: plt.plot(x, y, 'b--') will plot a blue dashed line. Line style options (non-exhaustive): '-' solid line '--' dashed line '-.' dash-dot line ':' dotted line '.' point marker 'o' circle marker '^' triangle marker 'v' upside-down triangle marker ('<' and '>' also allowed for left and right markers) 's' square marker 'p' pentagon marker '*' star marker '+' plus marker 'x' x marker 'D' or 'd' diamond marker Color options (RGB tuples and hex strings also allowed): 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black 'w' white To change line width: Include a linewidth in call to plot, e.g: plt.plot(x,y,linewidth=3) for a 3-point width line. To specify axis labels and title: plt.xlabel('xlabel') plt.ylabel('ylabel') plt.title('title') Note: Use LaTeX syntax for anything fancy (like symbols, super/subscript, etc.) To change font size of labels or legends: Include fontsize in call to xlabel, ylabel, title, or legend, e.g: plt.xlabel('xlabel', fontsize=12) To change size, placement, and labeling of axis ticks: Call tick_params, e.g: plt.tick_params(axis = 'both', which = 'both', length = 8, width = 2, pad = 5, labelsize = 12) 'axis' specifies which axis to apply these parameters to (options are 'x', 'y', or 'both', default is both) 'which' specifies which ticks to apply these parameters to (options are 'major', 'minor', or 'both', default major) 'length' specifies length of ticks in points 'width' specifies width of ticks in points 'pad' specifies tick label distance from axis in points 'labelsize' specifies font of tick labels in points To include a legend: Include a label in call to plot, e.g: plt.plot(x,y,label='label1') Then call legend using the label: plt.legend('label1') Note: Requires multiple calls to 'plot' for multiple lines-- can't put them all in one call to 'plot' if you want to label them. To specify legend position: Include loc in call to legend, e.g: plt.legend('label1', loc=4) where numbers specify locations: 0 best 1 upper right 2 upper left 3 lower left 4 lower right 5 right 6 center left 7 center right 8 lower center 9 upper center 10 center To turn on/off legend frame: Include frameon in call to legend, e.g: plt.legend('label1',frameon=False) will turn the frame off.