6

I recently switched from MATLAB to Python for data analysis and I am using matplotlib for visualization of the data. This works fine if the number of data points I would like to visualise are low. However, if I would like to visualize e.g.

import matplotlib.pyplot as plt
signal = [round(random.random() * 100) for i in xrange(0, 1000000)]
plt.plot(signal)
plt.show()

I am getting an error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
    return self.func(*args)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 276, in resize
    self.show()
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 348, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 451, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1034, in draw
    func(*args)
  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2086, in draw
    a.draw(renderer)
  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 562, in draw
    drawFunc(renderer, gc, tpath, affine.frozen())
  File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 938, in _draw_lines
    self._lineFunc(renderer, gc, path, trans)
  File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 978, in _draw_solid
    renderer.draw_path(gc, path, trans)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 145, in draw_path
    self._renderer.draw_path(gc, path, transform, rgbFace)
OverflowError: Allocated too many blocks

Can you give me an advise what you would do in this case? Are you down sampling your data? If I perform the same plot in MATLAB even with more data points, I haven't had this problem before.

2 Answers 2

2

Not sure exactly what you are trying to show but you can change the plot to '.' and it will work.

import random
import pylab as plt
signal = [round(random.random() * 100) for i in xrange(0, 1000000)]
plt.plot(signal, '.')
plt.show()

You may be able to get what you want by customising using the matlotlibrc file, the docs are here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. Your suggestion works but it is still quite slow (e.g. in comparison to MATLAB). The reason why I want to visualize so many data points is that I have a recording for about an hour acquired with a high sampling rate. I would like to have a quick look at the overall data to see whether the overall signal looks ok, before I zoom in at certain positions for a closer inspection of parts of the signal. Thanks for the link to the matplotlibrc.
1

I think scatter plot is faster

import matplotlib.pyplot as plt
x=np.random.normal(0,1,1000000)
y=np.random.normal(0,1,1000000)
plt.scatter(x,y)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.