I have a dataframe (data) in pandas that has a datetimeindex (ca. 25.000 days of data) and 527 columns of IDs.
work_id_10 work_id_100 work_id_1007 work_id_1009
concert_date
1917-01-27 0 0 0 0
1917-01-28 0 0 0 0
1917-01-29 0 0 0 0
1917-01-30 0 0 0 0
1917-01-31 0 0 0 0
Each column ID indicates presence or absence of the particular ID with either 0 (absence) or 1 (presence). So, basically what I have is a matrix of binary values.
I now want to create a plot that has all dates on the x-axis and for each column-ID the presences as points.I am using ipython.
%matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_yticklabels(data.index)
ax.set_xticklabels(data.columns)
plt.imshow/data, cmap='Greys', interpolation='none')
This gives me a MemoryError:
Traceback (most recent call last):
File "C:\Python27\Lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "C:\Python27\Lib\lib-tk\Tkinter.py", line 533, in callit
func(*args)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 365, in idle_draw
self.draw()
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 349, in draw
FigureCanvasAgg.draw(self)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line
469, in draw
self.figure.draw(self.renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1079, in draw
func(*args)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 2092, in d
raw
a.draw(renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\image.py", line 367, in draw
self._draw_unsampled_image(renderer, gc)
File "C:\Python27\lib\site-packages\matplotlib\image.py", line 321, in _draw_u
nsampled_image
self._get_unsampled_image(self._A, extent_in_ic, viewLim_in_ic)
File "C:\Python27\lib\site-packages\matplotlib\image.py", line 219, in _get_un
sampled_image
x = (x * 255).astype(np.uint8)
MemoryError
Is this the right approach, and why do I get a MemoryError?
Thank you!


fig, ax = plt.subplots()then yourplt.plot(...)you want to set your y axis tick labels like thisax.set_yticklabels(something)where something is your list of column names.dataof four-by-four ones and zeros; still broken? Etc. Replace the '/' in the last sample line with a '('. (I strongly recommend working in a script file instead of the interpreter. Others differ, but while you're learning, don't set yourself up for cut-and-paste errors.)