Skip to content

Code samples to understand the matplotlib.pyplot interface for plotting figures

Notifications You must be signed in to change notification settings

nabeeln7/pyplot-tutorial

Repository files navigation

pyplot tutorial

Code samples to understand the matplotlib.pyplot interface for plotting figures.

Terminology

This picture from the usage guide describes all of the major elements in a matplotlib plot: alt text

matplotlib

  • Object-oriented Python Library for plotting
  • Figure and Axes are the main objects
  • Figure: The "canvas" which contains the plots. It provides “figure level” operations.
    e.g.: set figure size, figure title etc.
  • Axes: What we generally think of as a "plot". A figure can have one or more Axes. All of the plotting operations are done on the Axes object.
    e.g.: plot, hist, scatter etc.

matplotlib.pyplot

  • pyplot is an interface which provides MATLAB-like syntax for matplotlib
  • There is a concept of a current Figure when using pyplot. If you don't specify any Figure, plt automatically creates a Figure (figure with index 1) and all further operations are performed on it.
  • Any operation is performed on the current Figure and the current Axes
    e.g.: plt.plot()
  • There are certain operations not supported by the pyplot interface. These are operations that you can be perform on the Figure object or the Axes object. You can access the current Figure or the current Axes using plt.gcf() and plt.gca() and operate on them. gcf() stands for "get current figure" and gca stands for "get current axes".
    e.g.: plt.gca().yaxis.set\_major\_locator(MultipleLocator(10)) accesses the current Axes object, accesses the y-axis Axis object for the Axes, and then sets the major ticks at an interval of 10.

References

Most of the code samples are taken from this excellent matplotlib tutorial
matplotlib Usage Guide
Difference between drawing plots using plot, axes, and figure in matplotlib?
Load csv file with numpy

Plotting a Cumulative Distributive Function (CDF):
Understanding a CDF
CDF with pyplot
CDF in python

About

Code samples to understand the matplotlib.pyplot interface for plotting figures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages