How to Display a Plot in Python

Опубликовано: 21 Март 2026
на канале: ActiveState
5,246
7

Pythonistas typically use the Matplotlib plotting library to display numeric data in plots, graphs and charts in Python. A wide range of functionality is provided by matplotlib’s two APIs (Application Programming Interfaces):

Pyplot API interface, which offers a hierarchy of code objects that make matplotlib work like MATLAB.

OO (Object-Oriented) API interface, which offers a collection of objects that can be assembled with greater flexibility than pyplot. The OO API provides direct access to matplotlib’s backend layer.

The pyplot interface is easier to implement than the OO version and is more commonly used.

Matplotlib also supports more advanced plots, such as scatter plots. In this case, the scatter() function is used to display data values as a collection of x,y coordinates represented by standalone dots.

In the example shown in this video, 2 arrays of the same length (one array for X axis values and another array for Y axis values) are plotted. Each value is represented by a dot.

Matplotlib is highly flexible, and can accommodate multiple datasets in a single plot. In the example shown in this video, we’ll plot two separate data sets, xdata1 and xdata2:

A histogram is used to display frequency distributions in a bar graph.

In the related example shown in this video, we’ll combine matplotlib’s histogram and subplot capabilities by creating a plot containing five bar graphs. The areas in the bar graph will be proportional to the frequency of a random variable, and the widths of each bar graph will be equal to the class interval

Matplotlib can also handle 3D plots by allowing the use of a Z axis. We’ve already created a 2D scatter plot above, but in the example shown in this video we’ll create a 3D scatter plot.

Get the code snippets for this Python tutorial here - https://www.activestate.com/resources...

Use ActivePython and accelerate your Python projects.
The #1 Python solution used by innovative enterprise teams
Comes pre-bundled with top Python packages
Spend less time resolving dependencies and more time on quality coding

Take a look at ActivePython: https://www.activestate.com/products/...