Skip to content

Informatics Practices · Ch 4 — Plotting Data using Matplotlib

Summary

Summary

  • A plot is a graphical representation of a data set, also known as a graph or chart, used to show the relationship between two or more variables.
  • To use Python's data-visualisation library, import the pyplot module from Matplotlib: import matplotlib.pyplot as plt, where plt is an alias (any alias name can be used).
  • The pyplot module houses functions to create a figure (plot), create a plotting area in a figure, plot lines/bars/histograms etc. in that area, and decorate the plot with labels.
  • The components of a plot include: Title, Legend, Ticks, x label, y label.
  • plt.plot() is used to build a plot.
  • plt.show() is used to display the figure.
  • plt.xlabel() and plt.ylabel() set the x and y label of the plot.
  • plt.title() displays the title of a plot.
  • It is possible to plot data directly from a DataFrame.
  • Pandas has a built-in .plot() function as part of the DataFrame class. …