Matplotlib attribute error; 'list' object has no attribute 'tolist'

Screen Link:

My Code:

sib_dict = {0: 608, 1: 209, 2: 28, 4: 18, 3: 16, 8: 7, 5: 5}

import matplotlib.pyplot as plt

lists = sorted(sib_dict.items()) # sorted by key, return a list of tuples

x, y = zip(*lists) # unpack a list of pairs into two tuples

plt.plot(x, y)
plt.show()

What I expected to happen:
I expected to see a visualization of the information contained in the dictionary.

What actually happened:
-received an AttributeError: ‘list’ object has no attribute ‘tolist’

AttributeError                            Traceback (most recent call last)
<ipython-input-8-3faa3ec63aee> in <module>
      6 
      7 plt.plot(x, y)
----> 8 plt.show()

/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/pyplot.py in show(*args, **kw)
    270     """
    271     global _show
--> 272     return _show(*args, **kw)
    273 
    274 

/dataquest/system/libs/dq_matplotlib_backend.py in show(*args, **kw)
    119         figures = []
    120         for figure_manager in Gcf.get_all_fig_managers():
--> 121             figure_manager.canvas.draw()
    122             figures.append(figure_manager.canvas.figure)
    123 

/dataquest/system/libs/dq_matplotlib_backend.py in draw(self)
    189         results = super().draw()
    190 
--> 191         record_hashes(
    192             figure_manager.canvas.get_renderer().image_hash()
    193             for figure_manager in Gcf.get_all_fig_managers()

/dataquest/system/libs/dq_matplotlib_backend.py in record_hashes(hashes)
    305         os.path.join(os.path.sep, "dataquest", "results", "image-hashes.lst"), "a"
    306     ) as f:
--> 307         f.writelines(hash_ + "\n" for hash_ in hashes)
    308 
    309 

/dataquest/system/libs/dq_matplotlib_backend.py in <genexpr>(.0)
    305         os.path.join(os.path.sep, "dataquest", "results", "image-hashes.lst"), "a"
    306     ) as f:
--> 307         f.writelines(hash_ + "\n" for hash_ in hashes)
    308 
    309 

/dataquest/system/libs/dq_matplotlib_backend.py in <genexpr>(.0)
    190 
    191         record_hashes(
--> 192             figure_manager.canvas.get_renderer().image_hash()
    193             for figure_manager in Gcf.get_all_fig_managers()
    194         )

/dataquest/system/libs/dq_matplotlib_backend.py in image_hash(self)
     63 
     64     def image_hash(self):
---> 65         hash_ = image_hash(list(self._dq_log))
     66         self._dq_log.clear()
     67         return hash_

/dataquest/system/libs/dq_matplotlib_backend.py in image_hash(image_log)
    298 
    299 def image_hash(image_log):
--> 300     return "dq-image-{}".format(hashobj(normalize(image_log)))
    301 
    302 

/dataquest/system/libs/dq_matplotlib_backend.py in normalize(log)
    290 
    291 def normalize(log):
--> 292     return sorted({json.dumps(dict(Element(el)), sort_keys=True) for el in log})
    293 
    294 

/dataquest/system/libs/dq_matplotlib_backend.py in <setcomp>(.0)
    290 
    291 def normalize(log):
--> 292     return sorted({json.dumps(dict(Element(el)), sort_keys=True) for el in log})
    293 
    294 

/dataquest/system/libs/dq_matplotlib_backend.py in __iter__(self)
    224         for method in self.fields():
    225             try:
--> 226                 yield (method, getattr(self, method)())
    227             except KeyError:
    228                 pass

/dataquest/system/libs/dq_matplotlib_backend.py in path(self)
    249 
    250     def path(self):
--> 251         return [polygon.tolist() for polygon in self._getfield("path").to_polygons()]
    252 
    253     def mpath(self):

/dataquest/system/libs/dq_matplotlib_backend.py in <listcomp>(.0)
    249 
    250     def path(self):
--> 251         return [polygon.tolist() for polygon in self._getfield("path").to_polygons()]
    252 
    253     def mpath(self):

AttributeError: 'list' object has no attribute 'tolist'

-seems to come from the plt.show() line of code
-stack overflow is suggesting that there is a deprecation issue for matplotlib (I have updated my computer (but i believe its dataquest’s server))
-the same code runs fine in Anaconda’s Jupyter Notebook, I am not able to complete this guided project because of the issue.

Hi lahguitarist
Please provide the screen link to help us help you. Please refer Guidelines for asking a technical question in our Community

1 Like

Screen Link: https://app.dataquest.io/c/44/m/188/guided-project%3A-creating-a-kaggle-workflow/3/exploring-the-data

My apologies.

I am not able to complete this guided project because of the issue.

I was able to run your code and it worked fine.

Could you refresh and run it again.

Still having that issue. Like I said I was able to run it on my local system (so I don’t think it’s the code), but on the website it won’t run. I have tried both Firefox and Safari browsers

Might be a cache issue then, you could log out from Dataquest, close the screen and start in a new window.

I am getting the same error in the DQ environment with your code. Not sure why currently. Dash’s reply about the cache might help but I didn’t try that myself.

After importing pyplot, add the following

%matplotlib inline

Run all the code cells again.

I tried with that and didn’t get any error. Would recommend adding the above line whenever working with matplotlib in Jupyter Notebooks.

o m g how did I not think of that. :man_facepalming:

that’s been driving me nuts. Thank you!