Applying pseudocolor schemes to image plots ¶ Pseudocolor can be a useful tool for enhancing contrast and visualizing your data more easily. This is especially useful when making presentations of your data using projectors - their contrast is typically quite poor. Pseudocolor is only relevant to single-channel, grayscale, luminosity images. This will generate plot-1.png, plot2.png, and so on. For import into PDF-incapable programs (MS Office) Some programs which cannot import PDF files may work with high-resolution PNG or TIFF files. For example, Microsoft Office cannot import PDF files. For print publications, you may be required to use 300dpi images.

Here you'll find a host of example plots with the code thatgenerated them.

Line Plot¶

Here's how to create a line plot with text labels usingplot().

Multiple subplots in one figure¶

Multiple axes (i.e. subplots) are created with thesubplot() function:

Images¶

Matplotlib can display images (assuming equally spacedhorizontal dimensions) using the imshow() function.

Contouring and pseudocolor¶

The pcolormesh() function can make a coloredrepresentation of a two-dimensional array, even if the horizontal dimensionsare unevenly spaced. Thecontour() function is another way to representthe same data:

Example comparing pcolormesh() and contour() for plotting two-dimensional data

Histograms¶

The hist() function automatically generateshistograms and returns the bin counts or probabilities:

Paths¶

Burial Plots Images

You can add arbitrary paths in Matplotlib using thematplotlib.path module:

Three-dimensional plotting¶

The mplot3d toolkit (see Getting started and3D plotting) has support for simple 3d graphsincluding surface, wireframe, scatter, and bar charts.

Thanks to John Porter, Jonathon Taylor, Reinier Heeres, and Ben Root forthe mplot3d toolkit. This toolkit is included with all standard Matplotlibinstalls.

Streamplot¶

Plot Images In Subplot Matplotlib

The streamplot() function plots the streamlines ofa vector field. In addition to simply plotting the streamlines, it allows youto map the colors and/or line widths of streamlines to a separate parameter,such as the speed or local intensity of the vector field.

This feature complements the quiver() function forplotting vector fields. Thanks to Tom Flannaghan and Tony Yu for adding thestreamplot function.

Python plot image

Ellipses¶

In support of the Phoenixmission to Mars (which used Matplotlib to display ground tracking ofspacecraft), Michael Droettboom built on work by Charlie Moad to providean extremely accurate 8-spline approximation to elliptical arcs (seeArc), which are insensitive to zoom level.

Bar charts¶

Use the bar() function to make bar charts, whichincludes customizations such as error bars:

You can also create stacked bars(bar_stacked.py),or horizontal bar charts(barh.py).

Pie charts¶

The pie() function allows you to create piecharts. Optional features include auto-labeling the percentage of area,exploding one or more wedges from the center of the pie, and a shadow effect.Take a close look at the attached code, which generates this figure in justa few lines of code.

Hazard Ratio Plots Images

Tables¶

The table() function adds a text tableto an axes.

Scatter plots¶

Garden

The scatter() function makes a scatter plotwith (optional) size and color arguments. This example plots changesin Google's stock price, with marker sizes reflecting thetrading volume and colors varying with time. Here, thealpha attribute is used to make semitransparent circle markers.

GUI widgets¶

Matplotlib has basic GUI widgets that are independent of the graphicaluser interface you are using, allowing you to write cross GUI figuresand widgets. See matplotlib.widgets and thewidget examples.

Filled curves¶

The fill() function lets youplot filled curves and polygons:

Thanks to Andrew Straw for adding this function.

Date handling¶

You can plot timeseries data with major and minor ticks and customtick formatters for both.

See matplotlib.ticker and matplotlib.dates for details and usage.

Log plots¶

Plot Numpy Array Image

Line plots images

The semilogx(),semilogy() andloglog() functions simplify the creation oflogarithmic plots.

Thanks to Andrew Straw, Darren Dale and Gregory Lielens for contributionslog-scaling infrastructure.

Polar plots¶

Box

The polar() function generates polar plots.

Legends¶

The legend() function automaticallygenerates figure legends, with MATLAB-compatible legend-placementfunctions.

Thanks to Charles Twardy for input on the legend function.

TeX-notation for text objects¶

Below is a sampling of the many TeX expressions now supported by Matplotlib'sinternal mathtext engine. The mathtext module provides TeX style mathematicalexpressions using FreeTypeand the DejaVu, BaKoMa computer modern, or STIXfonts. See the matplotlib.mathtext module for additional details.

Matplotlib's mathtext infrastructure is an independent implementation anddoes not require TeX or any external packages installed on your computer. Seethe tutorial at Writing mathematical expressions.

Native TeX rendering¶

Although Matplotlib's internal math rendering engine is quitepowerful, sometimes you need TeX. Matplotlib supports external TeXrendering of strings with the usetex option.

EEG GUI¶

You can embed Matplotlib into pygtk, wx, Tk, or Qt applications.Here is a screenshot of an EEG viewer called pbrain.

The lower axes uses specgram()to plot the spectrogram of one of the EEG channels.

For examples of how to embed Matplotlib in different toolkits, see:

Line Plots Images

XKCD-style sketch plots¶

Plot Images In Matlab

Just for fun, Matplotlib supports plotting in the style of xkcd.

Subplot example¶

Many plot types can be combined in one figure to createpowerful and flexible representations of data.

Corner Plots Images

Keywords: matplotlib code example, codex, python plot, pyplotGallery generated by Sphinx-Gallery