Jupyter Notebook suddenly only display an incomplete graph. How to solve it?

Screen Link: Learn data science with Python and R projects

Hi!

I need some helps to fix my graph!

While I was in the process of working on the Guided Project: Storytelling Data Visualization on Exchange Rates, my MacBook suddenly had some charging problem, therefore, I sent my MacBook for checking and reformatting. I restored all my data/software with Time Machine afterwards. Unfortunately, strange things happened with my graphs afterwards.

I am using Jupyter Notebook 2.3.0 through Anaconda Navigator 2.0.3.

Before reformatting my MacBook, my graph looked like this:

After reformatting my MacBook, the graph looks the same as above when I open the Jupyter Notebook. However, it looks weird after I clicked Restart & Run All:

i. The graph was shown in a very tiny icon, almost not visible.

ii. When one clicks on the small icon, a graph appears. The appearance of the graph changed, many elements disappeared, such as title, subtitle and in-text description, grid and signature bar.

There is no error message, so I couldn’t check the error.

What could I have gone wrong?

How could I fix it?

Please let me know if I should share my note with you.

All the best,
Shi

Hi @shipWship, I’m sorry you’re having trouble after such a traumatic experience (reinstalling/recovering an operating system can be a nightmare!)

Have you tried rerunning the entire notebook? (ie run all cells) It just looks like some cells just need to be run again…it can’t be that simple can it?!

Maybe it’s a good idea to share your notebook to see if it’s a problem with your code or with your environment.

Hi @mathmike314,

Thanks for your offer to help! I have been checking on Google, but couldn’t find a solution yet.

When I open the original Jupyter Notebook, the graphs (In[35] and In[38]) are fine. They only become weird after I restart and re-run the entire notebook, which are:

  • In[35]: The text disappeared from the graph (as described above)
  • In[38]: Suddenly error message shows up for the lines of codes there. It was completely fine in the original file.

The error message for In[38] is as below:

<ipython-input-38-4fb5050e8bee>:28: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax1.set_xticklabels(['', '2001', '', '2003', '', '2005', '', '2007', '', '2009'])
<ipython-input-38-4fb5050e8bee>:80: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax2.set_xticklabels(['', '2009', '', '2011', '', '2013', '',
<ipython-input-38-4fb5050e8bee>:104: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax3.set_xticklabels(['2017', '', '2018', '', '2019', '',

It seems selectively affecting some of my charts only, as some charts (simpler charts) on the same guided project are fine, as well as charts from my Data Visualization exercises. Out of curiosity, I randomly downloaded two guided projects from other students and opened them, and I had similar problems after restart and re-run the entire notebook.

Here is some info about my environment:

  • Matplotlib 3.4.3
  • Python 3.8.8
  • Jupyter Notebook 2.3.0
  • Anaconda Navigator 2.0.3

You could find my notebook here:

Cheers,
Shi

Click here to view the jupyter notebook file in a new tab

Did you happen to find this SO post about the error? They offer a few workarounds but nothing that could really explain why you’re getting the error in the first place.

I’m by no means an expert and I’ve never personally run into this type of error before, but my instincts are telling me this could be a dependencies issue…perhaps something wasn’t updated/was overwritten during the recovery of the OS? Check out this list of dependencies for Matplotlib 3.4.3 to see if you have them.

As an experiment, I ran your notebook on Google Colab and got an error on your last code cell [38]:

NameError                                 Traceback (most recent call last)
<ipython-input-38-4fb5050e8bee> in <module>()
    134 
    135 # Highlighting the global economy crisis period
--> 136 for s, e in zip(start_year_dt, end_year_dt):
    137     ax.axvspan(xmin=s, xmax=e, ymin=0, ymax=0.986, alpha=0.12, color='grey')
    138 

NameError: name 'start_year_dt' is not defined
1 Like

Hi @mathmike314 ,

Thanks for sharing the SO post! With the workarounds, I managed to solve the chart issue from In [38]. :slight_smile:

Apparently, after reformatting my MacBook, my older version of Matplotlib has been updated to a newer version. The issue that I am facing is a warning from the newer version (which was fine in the older version).

Same as the issue from In [35], the newer version of Matplotlib somehow messed up the x-coordinates of all the ax.text().

After a very detailed check, I found that there was a tiny shadow at the right corner (barely visible):

When I open the output image and scroll to the end at the right corner, I saw this:

This means that the text has always been there, but I just didn’t notice it! What a ‘funny’ issue! :sweat_smile: :sweat_smile: After adjusting the x-value of the ax.text(), all the text came back to its original location.

So much to learn in programming! Thanks again for your help! Happy coding! :smiley:

1 Like