Examples#
For an overview of the plotting methods we provide, see Plot types
This page contains example plots. Click on any image to see the full image and source code.
For longer tutorials, see our tutorials page. You can also find external resources and a FAQ in our user guide.
Tagging!
You can also browse the example gallery by tags.
Lines, bars and markers#
Plotting categorical variables
Plotting the coherence of two signals
Filling the area between lines
Discrete distribution as horizontal bar chart
Customizing dashed line styles
Lines with a ticked patheffect
Plotting masked and NaN values
Mapping marker properties to multivariate data
Shade regions defined by a logical mask using fill_between
Creating a timeline with lines, dates, and text
Images, contours and fields#
Interactive Adjustment of Colormap Range
Colormap normalizations SymLogNorm
Contouring the solution space of optimizations
Blend transparency with color in 2D images
Modifying the coordinate formatter
Contour plot of irregularly spaced data
Visualize matrices with matshow
Multiple images with one colorbar
Advanced quiver and quiverkey functions
Subplots, axes and figures#
Programmatically controlling subplot adjustment
Controlling view limits using margins and sticky_edges
Resizing Axes with constrained layout
Resizing Axes with tight layout
Different scales on the same Axes
Figure size in different units
Figure labels: suptitle, supxlabel, supylabel
Combining two subplots using subplots and GridSpec
Using Gridspec to make multi-column/row subplot layouts
Managing multiple figures in pyplot
Creating multiple subplots using plt.subplots
Statistics#
Percentiles as horizontal bar chart
Artist customization in box plots
Box plots with custom fill colors
Box plot vs. violin plot comparison
Separate calculation and plotting of boxplots
Plot a confidence ellipse of a two-dimensional dataset
Different ways of specifying error bars
Including upper and lower limits in error bars
Creating boxes from error bars using PatchCollection
Plotting cumulative distributions
Demo of the histogram function's different histtype settings
The histogram (hist) function with multiple data sets
Histogram bins, density, and weight
Producing multiple histograms side by side
Pie and polar charts#
Error bar rendering on polar axis
Text, labels and annotations#
Angle annotations on bracket arrows
The difference between \dfrac and \frac
Labeling ticks using engineering notation
Annotation arrow style reference
Fonts demo (object-oriented style)
Fonts demo (keyword arguments)
Legend using pre-defined labels
Concatenating text objects with different properties
Rendering math equations using TeX
Controlling style of text and labels using a dictionary
Text Rotation Relative To Line
Color#
For a description of the colormaps available in Matplotlib, see the colormaps tutorial.
Colors in the default property cycle
Creating a colormap from a list of colors
Selecting individual colors from a colormap
Ways to set a color's alpha value
Shapes and collections#
Reference for Matplotlib artists
Line, Poly and RegularPoly Collection with autoscaling
Ellipse with orientation arrow demo
Plotting multiple lines with a LineCollection
Style sheets#
Bayesian Methods for Hackers style sheet
Module - pyplot#
Text and mathtext using pyplot
Module - axes_grid1#
HBoxDivider and VBoxDivider demo
Showing RGB channels using RGBAxes
Controlling the position and size of colorbars with Inset Axes
Per-row or per-column colorbars
Axes with a fixed physical size
Setting a fixed aspect on ImageGrid cells
Make room for ylabel using axes_grid
Scatter Histogram (Locatable Axes)
Module - axisartist#
Simple axis tick label and tick directions
Showcase#
Integral as the area under a curve
Shaded & power normalized rendering
Pan/zoom events of overlapping axes
Animation#
Animated image using a precomputed list of images
Pausing and Resuming an Animation
Event handling#
Matplotlib supports event handling with a GUI neutral event model, so you can connect to Matplotlib events without knowledge of what user interface Matplotlib will ultimately be plugged in to. This has two advantages: the code you write will be more portable, and Matplotlib events are aware of things like data coordinate space and which axes the event occurs in so you don't have to mess with low level transformation details to go from canvas space to data space. Object picking examples are also included.
Figure/Axes enter and leave events
Miscellaneous#
Changing colors of lines intersecting a box
Building histograms using Rectangles and PolyCollections
Rasterization for vector graphics
3D plotting#
Create 2D bar graphs in different planes
Plot contour (level) curves in 3D
Plot contour (level) curves in 3D using the extend3d option
Project contour profiles onto a graph
Project filled contour onto a graph
Custom hillshading in a 3D surface plot
Create 3D histogram of 2D data
Generate polygons to fill under 3D line graph
3D surface with polar coordinates
Triangular 3D filled contour plot
3D voxel plot of the NumPy logo
3D voxel / volumetric plot with RGB colors
3D voxel / volumetric plot with cylindrical coordinates
3D wireframe plots in one direction
Scales#
These examples cover how different scales are handled in Matplotlib.
Specialty plots#
Radar chart (aka spider or star chart)
Long chain of connections using Sankey
SkewT-logP diagram: using transforms and custom projections
Spines#
Ticks#
Automatically setting tick positions
Centering labels between ticks
Formatting date ticks using ConciseDateFormatter
Placing date ticks using recurrence rules
Date tick locators and formatters
Custom tick formatter for time series
Set default y-axis tick labels on the right
Setting tick labels from a list of values
Move x-axis tick labels to the top
Units#
These examples cover the many representations of units in Matplotlib.
Embedding Matplotlib in graphical user interfaces#
You can embed Matplotlib directly into a user interface application by following the embedding_in_SOMEGUI.py examples here. Currently Matplotlib supports PyQt/PySide, PyGObject, Tkinter, and wxPython.
When embedding Matplotlib in a GUI, you must use the Matplotlib API directly rather than the pylab/pyplot procedural interface, so take a look at the examples/api directory for some example code working with the API.
Embedding in GTK3 with a navigation toolbar
Embedding in GTK4 with a navigation toolbar
mplcvd -- an example of figure hook
Embedding in a web application server (Flask)
Widgets#
Examples of how to write primitive, but GUI agnostic, widgets in matplotlib
Select indices from a collection using polygon selector
Thresholding an Image with RangeSlider
Rectangle and ellipse selectors
Snapping Sliders to Discrete Values
Userdemo#
Connection styles for annotations