English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

模块pylab Matplotlib

PyLab is the process interface for Matplotlib's object-oriented plotting library. Matplotlib is the entire package; matplotlib.pyplot is a module in Matplotlib; it and PyLab are modules installed with Matplotlib.

PyLab is a very convenient module that can import matplotlib.pyplot (for drawing) and NumPy (for mathematics and using arrays) in a single namespace. Although there are many examples using PyLab, it is no longer recommended to use it.

Basic drawing

Drawing curves is done using the plot command, which requires a pair of arrays (or sequences) of the same length, as shown in the following example code -

# Nombre de archivo : example.py
# Derechos de autor : 2020 Por w3codebox
# Autor por: es.oldtoolbag.com
# Fecha : 2020-08-08
#! /usr/bin/env python
 #coding=utf-8
 from numpy import *
 importar pylab *
 x = linspace(-3, 3, 30)
 y = x**2
 #plt.title('title')
 plot(x, y)
 mostrar()

Execute the above code line to generate the following result -

If you want to draw symbols instead of lines, please provide other string parameters, the available symbol parameters are as follows:

Symbols: ^ , v , < , > , s , + , x , D , d , 1 , 2 , 3 , 4 , h , H , p , | , _ , - , –, -, , . , , , o , Color: b, g, r, c, m, y, k, w

Ahora veamos el siguiente código -

# Nombre de archivo : example.py
# Derechos de autor : 2020 Por w3codebox
# Autor por: es.oldtoolbag.com
# Fecha : 2020-08-08
importar pylab *
 x = linspace(-3, 3, 30)
 y = x**2
 dibujar(x, y, 'r|')
 mostrar()

Ejecutar el código de ejemplo anterior, obtener el siguiente resultado -

Se puede cubrir el gráfico. Simplemente use múltiples comandos de dibujo. Use clf() para borrar el dibujo.

# Nombre de archivo : example.py
# Derechos de autor : 2020 Por w3codebox
# Autor por: es.oldtoolbag.com
# Fecha : 2020-08-08
#! /usr/bin/env python
 #coding=utf-8
 importar pylab *
 x = linspace(-3, 3, 30)
 y = x**2
 dibujar(x, sen(x))
 dibujar(x, cos(x), 'r-')
 dibujar(x, -sen(x), 'g--')
 mostrar()

Las líneas de código anteriores generan la siguiente salida -