In Jupyter notebooks %matplotlib notebook
sets up the backend to render the visualizations into the browser.
There are several backends for matplotlib including even those that render to hardcopies like svg or png.
Matplotlib's naming conventions are matlabish than pythonic. We use getters and setters.
- Artist Layer
Abstraction to making drawing stuff easy.
There is a figure
object with one or more subplots. Each subplot is a series with one or more axes.
Also contains base items for drawing like rectangle, line, ellipse and collection of items like paths (a combination of lines)
plt.xlabel('X-axis name') # SEt x-axis label
plt.ylabel('Y-axis name') # SEt y-axis label
plt.plot(ds, color='blue', label='Original') # Plot Indexed dataset ds with a blue line. Label is displayed in the legend. Index column becomes the X-axis
plt.legend(loc='best') # Display legend in the 'best' location
plt.title('Plot Title') # Set Plot's title
If you want subplots:
plt.subplot(2,1,1) # 2 Rows, 1 Column, 1st Plot
plt.plot(ds_logscale, color='blue')
plt.subplot(2,1,2) # 2 Rows, 1 Column, 2nd Plot
plt.plot(ds_logscale_diff_shift)
plt.show()
To draw lines on the graph at arbitrary postions either horizontal or vertical:
plt.axhline(y=1, linestyle='--', color='gray') # Draws a dashed gray horizontal line at y=1, parallel to X-axis.
plt.axvline(x=1, linestyle='--', color='gray') # Draws a dashed gray vertical line at x=1, parallel to Y-axis.