2016-03-29 21 views
13

Prima di pubblicare questa domanda, ho controllato tutte le possibili domande duplicate e ho provato tutto il metodo e non ho ancora potuto risolvere il problema."OverflowError: Allocato troppi blocchi":

Ho una trama semplice in matplotlib. Quando commento la linea chiamando lo plt.fill_between(), il codice funziona perfettamente, ma quando annoto questo errore di overflow.

Nota: Questo errore si verifica nel mio portatile con Ubuntu 15.10
Tuttavia, in MacOS ho provato lo stesso codice e si vede nessun errore

Update (sorprendente!): ho usato backend come TkAgg .

print(mpl.rcParamsDefault) 
# Answer is agg. 

Il mio codice è il seguente:

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

# Author : Bhishan Poudel 
# Date : Mar 28, 2016 
# Topic : OverflowError: Allocated too many blocks 
# Note : python --version ==> Python 2.7.10 
# Note : lsb_release -a ==> ubuntu 15.10 

# Imports 
import numpy as np 
import matplotlib as mpl 
import matplotlib.pyplot as plt 

# plot values 
x = np.arange(0.001, 25.0, 0.01) 
A = 4.3 
y = np.array((-1.0/x) + (0.5*A*A/(x**2)) - (A*A/(x**3))) 

# Plots 
plt.plot(x,y,color='k') 

# Set axes limits 
plt.ylim(-0.04,0.06) 

# Attempt to resolve OverflowError 
plt.rcParams['backend'] = 'TkAgg' # or, 'qt4agg' 
plt.rcParams['agg.path.chunksize'] = 100000 
# This did not worked! 

# Fill the color 
plt.fill_between(x, -0.04, y, color='darkgray', alpha=.5) 
# If I comment this line there will be no error! 

# Show the plot 
plt.show() 

I collegamenti che ho provato sono i seguenti:

Matplotlib OverflowError: Allocated too many blocks
pyplot savefig allocating too many blocks
http://matplotlib.org/1.3.1/users/customizing.html

https://github.com/matplotlib/matplotlib/issues/5907
https://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template

Dopo aver attraversato questi collegamenti mio tentativo iniziale è simile a questo:

# Attempt to resolve OverflowError 
plt.rcParams['backend'] = 'TkAgg' # or, 'qt4agg' 
plt.rcParams['agg.path.chunksize'] = 100000 
# This did not worked! 

Tentativo # 2:
Ho creato un file ~/.matplotlib/matplotlibrc poi collocato seguente codice all'interno di esso:

agg.path.chunksize : 10000  # 0 to disable; values in the range 
            # 10000 to 100000 can improve speed slightly 
            # and prevent an Agg rendering failure 
            # when plotting very large data sets, 
            # especially if they are very gappy. 
            # It may cause minor artifacts, though. 
            # A value of 20000 is probably a good 
            # starting point. 

Tentativo n. 3: Ho installato anche il modulo seaborn

sudo -H pip install seaborn 

e studiato documentazione.
https://stanford.edu/~mwaskom/software/seaborn/tutorial.html
Tuttavia, non sono riuscito a trovare la risoluzione a questo problema.

Aggiornamento:
Il rapporto di errore è la seguente:

[email protected]:~/OneDrive/Programming/Python/pyprograms/plotting/matplotlib_customization$ /bin/sh /tmp/geany_run_script_R6KUEY.sh 
/usr/lib/python2.7/dist-packages/matplotlib/collections.py:571: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison 
    if self._edgecolors == str('face'): 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 338, in resizeEvent 
    self.draw() 
    File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5agg.py", line 148, in draw 
    FigureCanvasAgg.draw(self) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 469, in draw 
    self.figure.draw(self.renderer) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper 
    draw(artist, renderer, *args, **kwargs) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1079, in draw 
    func(*args) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper 
    draw(artist, renderer, *args, **kwargs) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2092, in draw 
    a.draw(renderer) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper 
    draw(artist, renderer, *args, **kwargs) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", line 751, in draw 
    Collection.draw(self, renderer) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper 
    draw(artist, renderer, *args, **kwargs) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", line 293, in draw 
    mpath.Path(offsets), transOffset, tuple(facecolors[0])) 
    File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 124, in draw_markers 
    return self._renderer.draw_markers(*kl, **kw) 
OverflowError: Allocated too many blocks 


------------------ 
(program exited with code: 0) 

Update: La trama richiesta è la seguente:
enter image description here

+1

Puoi includere anche il traceback che ottieni? Non riesco a riprodurlo su current master + python 3 – tacaswell

+0

matplotlib usa un altro backend per tracciare in macosx e linux, vedere https://github.com/matplotlib/matplotlib/issues/5907. Il problema sembra essere che il tuo file di dati è grande e se usi 'fill_between 'ci sono ancora più punti per tracciare –

+0

prova questo per vedere quale backend stai usando' plt.get_backend() ' –

risposta

3

non riesco a riprodurre l'errore sul mio computer , ma se vuoi cambiare il backend di matplotlib, è meglio farlo prima di importare pyplot.

Prova:

import numpy as np 
import matplotlib as mpl 
mpl.use('TkAgg') # I'd advise testing 'Gtk3Agg' or 'Qt4Agg' (or 5) instead 
import matplotlib.pyplot as plt 
print(mpl.get_backend()) # check that the change occurred 

EDIT: ok, ho trovato il problema, è perché la funzione è quasi divergendo in modo matplotlib pensa che ha una superficie enorme per coprire ... provare:

plt.fill_between(x, -0.04, np.clip(y,-0.04,0.06)) 
+0

Grazie per la risposta, ma questo non ha funzionato su Ubuntu 15.10, ho provato mpl.use ('Qt5Agg') # Vorrei consigliare test 'Gtk3Agg' o 'Qt4Agg' (o 5) invece, TkAgg mpl.rcParams [' agg.path.chunksize '] = 100000 # POI RESTO DEL CODICE. dà lo stesso vecchio errore di overflow. –

+0

Ok, e '' print'' conferma che il backend è cambiato? Hai provato senza modificare '' mpl.rcParams ['agg.path.chunksize'] '' con il nuovo back-end (solo per essere al sicuro)? Prova anche a sostituire '' color'' di '' facecolor'', dal momento che il tuo errore sembra essere relativo ai bordi ... – Silmathoron

+0

Cambiare colore in facecolor e nessuno dei backend Agg funziona! Se stai usando Ubuntu, qual è la tua versione di Ubuntu e la versione di matplotlib? –