matplotlib no muestra mis dibujos aunque yo llamo pyplot.Mostrar()


Necesito tu ayuda sobre matplotlib. Sí, no olvidé llamar al pyplot.Mostrar().

$ ipython --pylab

import matplotlib.pyplot as p 
p.plot(range(20), range(20))

Devuelve matplotlib.lines.Line2D at 0xade2b2c como salida.

p.show()

No Hay nada que suceda. No hay mensaje de error. No hay ventana nueva. Nada. Instalo matplotlib usando pip y no recibí ningún mensaje de error.

Detalles:

Utilizo,

  • Ubuntu
  • IPython v0. 11
  • Python v2.6. 6
  • matplotlib v1.0.1
Author: David Z, 2011-09-24

14 answers

Si pongo mi backend a template en ~/.matplotlib/matplotlibrc, entonces puedo reproducir sus síntomas:

~/.matplotlib/matplotlibrc:

# backend      : GtkAgg
backend      : template

Tenga en cuenta que el archivo matplotlibrc puede no estar en el directorio ~/.matplotlib/. En este caso, el siguiente código muestra dónde está:

>>> import matplotlib
>>> matplotlib.matplotlib_fname()

In [1]: import matplotlib.pyplot as p

In [2]: p.plot(range(20),range(20))
Out[2]: [<matplotlib.lines.Line2D object at 0xa64932c>]

In [3]: p.show()

Si edita ~/.matplotlib/matplotlibrc y cambia el backend a algo como GtkAgg, debería ver un gráfico. Puede enumerar todos los motores disponibles en su máquina con

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)

Debería devolver una lista como:

['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg',
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf',
'ps', 'svg', 'template']

Referencia:

 150
Author: unutbu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-27 02:00:57

Me encontré exactamente con el mismo problema en Ubuntu 12.04, porque instalé matplotlib (dentro de un virtualenv) usando

pip install matplotlib

Para hacer una historia corta, mi consejo es: no intente instalar matplotlib usando pip o a mano; deje que un gestor de paquetes real (por ejemplo, apt-get / synaptic) lo instale y todas sus dependencias por usted.

Desafortunadamente, los backends de matplotlib (métodos alternativos para representar realmente sus parcelas) tienen todo tipo de dependencias con las que pip no se ocupará. Incluso peor aún, falla silenciosamente; es decir, pip install matplotlib parece instalar matplotlib con éxito. Pero cuando intenta usarlo (por ejemplo, pyplot.show()), no aparecerá ninguna ventana de trazado. Probé todos los diferentes backends que la gente en la web sugiere (Qt4Agg, GTK, etc.), y todos fallaron (es decir, cuando traté de importar matplotlib.pyplot, obtengo ImportError porque está tratando de importar alguna dependencia que falta). Luego investigué cómo instalar esas dependencias, pero simplemente me hizo querer dejar de usar pip (dentro de virtualenv) como una solución de instalación viable para cualquier paquete que tenga dependencias de paquetes que no sean de Python.

Toda la experiencia me envió de vuelta a apt-get / synaptic (es decir, el gestor de paquetes de Ubuntu) para instalar software como matplotlib. Eso funcionó perfectamente. Por supuesto, eso significa que solo puede instalar en los directorios de su sistema, no virtualenv bondad, y usted está atascado con las versiones que Ubuntu distribuye, que puede estar muy por detrás de la versión actual...

 64
Author: Christopher Lee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-10 04:17:29

%matplotlib inline

Para mí trabajando con notebook, agregando la línea anterior antes de que funcione la trama.

 25
Author: grampus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-18 12:16:03

Para referencia futura,

He encontrado el mismo problema p pylab no se mostraba bajo ipython. El problema se solucionó cambiando el archivo de configuración de ipython {ipython_config.py}. En el archivo de configuración

c.InteractiveShellApp.pylab = 'auto'

Cambié 'auto' a ' qt ' y ahora veo gráficos

 9
Author: anon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-13 12:25:25

Simplemente escriba:

plt.ion()

Véase https://www.youtube.com/watch?v=1zmV8lZsHF4 a las 23:30 !

plt se utiliza debido a mi importación: import matplotlib.pyplot como plt

Estoy usando python2.7 en un mac con iTerm2.

 5
Author: tnuts,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-04 00:42:36

Lo que resolvió mi problema fue usar las dos líneas siguientes en el cuaderno ipython en la parte superior

%matplotib inline
%pylab inline

Y funcionó. Estoy usando Ubuntu16. 04 e ipython-5.1

 4
Author: Bhanu Pratap Singh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-16 05:30:31

Tuve que instalar matplotlib desde el código fuente para que esto funcionara. Las instrucciones clave (de http://www.pyimagesearch.com/2015/08/24/resolved-matplotlib-figures-not-showing-up-or-displaying/) son:

$ workon plotting
$ pip uninstall matplotlib
$ git clone https://github.com/matplotlib/matplotlib.git
$ cd matplotlib
$ python setup.py install

Al cambiar el backend, como dice @unutbu, me encontré con muchos más problemas con todos los diferentes backends que tampoco funcionan.

 2
Author: Rikki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-02 15:09:34

Agregar las siguientes dos líneas antes de importar pylab parece funcionar para mí

import matplotlib
matplotlib.use("gtk")

import sys
import pylab
import numpy as np
 1
Author: Pau,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-06 11:49:47

Asegúrese de tener habilitado este script de inicio : (Preferencias > Consola > Opciones avanzadas)

/usr/lib/python2.7/dist-packages/spyderlib/scientific_startup.py

Si el PYTHONSTARTUP estándar está habilitado, no tendrá una gráfica interactiva

 0
Author: Covich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-13 13:34:31

Al igual que @Rikki, resolví este problema actualizando matplotlib con pip install matplotlib --upgrade. Si no puede actualizar la desinstalación y reinstalación puede funcionar.

pip uninstall matplotlib
pip install matplotlib
 0
Author: Seanny123,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-08 05:16:19

Para mí el problema ocurre si simplemente creo un vacío matplotlibrc archivo bajo ~/.matplotlib en macOS. Añadiendo "backend: macosx" en él soluciona el problema.

Creo que es un error: si backend no se especifica en mi matplotlibrc debería tomar el valor predeterminado.

 0
Author: an0,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-13 20:30:24

Después de ejecutar su código incluya:

import pylab as p
p.show()
 0
Author: Shrish Trivedi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-25 11:53:20

Encontré que necesitaba window = Tk() y luego window.mainloop()

 0
Author: R Keene,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-15 20:26:21

Para Ubuntu 12.04:

sudo apt-get install python-qt4
virtualenv .env --no-site-packages
source .env/bin/activate
easy_install -U distribute
ln -s /usr/lib/python2.7/dist-packages/PyQt4 .
ln -s /usr/lib/python2.7/dist-packages/sip.so .
pip install matplotlib
 -1
Author: nanvel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-02 15:37:13