Matplotlib styles

Hello the community,

I am facing a problem. I am in the scatter dot plot mission and to play around I tried to change the BUT the problem is that I cannot revert to the previous style. I did use the style.available and style.use(‘Style_to_use’) but cannot go back to the default one used by the DataQuest platform.

Unfortunately this prevents me from getting right answers to the missions.

Anyone faced this problem before and now the trick here ? What is the default theme used in the platform ?

Many thanks



Hey Faouzi,

Unfortunately, the answer to this is a little bit complicated. While troubleshooting this, I learned from this stackoverflow thread that whenever you use %matplotlib inline, the inline interface uses its own styles, that are different to default (which you discovered) and once you have overwritten them it’s pretty difficult to get them back unless you know what they are.

Solving this outside of Dataquest is pretty straightforward (and useful to know if you run into this so, to start, I’m going to answer how I would fix this issue if I was working on my own computer in a Jupyter notebook (outside the main dataquest interface):

  1. Remove the code that references the style change
  2. Restart the Kernel and run all cells

Unfortunately, within the Dataquest interface it’s not as easy to reset your kernel. So that you can get un-stuck, I’ve experimented and found the following code which you can insert before yours which will restore things to the way they were:

styles = {'backend': 'module://dq_matplotlib_backend',
 'figure.edgecolor': 'white',
 'figure.facecolor': 'white',
 'figure.figsize': [6.0, 4.0],
 'figure.subplot.bottom': 0.125,
 'font.size': 10.0,
 'interactive': True,
 'savefig.dpi': 72.0}

import matplotlib as mpl'default')

What this code does is reset the styles to the default, then manually change those that are different in ‘inline’ to the inline styles. This should let you get unstuck in our interface.

I apologize that this was more painful than it needs to be, but hopefully learning a bit more about MPL styles was useful (it was for me, at least!)


Josh many thanks for your thorough answer.
I indeed spent a lot of time with the styles and parameters and learning about them. I read some interesting stuff about the backend aspect of plotting !

I did try tweaking the RcParams without success.
Using your code raises an error saying that module does not have attribute styles.

I will have a closer look to this using your parameters. I can also pass the styles dictionary to the function.

Dear Josh,

Do you think someone would be able to restart my DataQuest kernel ?



Dear Josh,

You had a typo here. :slight_smile:
But putting this code before does not work.
What a mess it really impairs the experience as I actually cannot validate the courses.


Hi Fouzi,

I apologize for my typo, I edited the original in case it trips someone else up in the future.

I actually tested this in the interface and was able to get it to work, so I’m a bit puzzled why it doesn’t work for you also. Are you sure you have removed the code that sets the style originally before adding my code? Here is a screenshot of me setting the style to something else, using my code to set it back, then plotting and getting a correct answer detected:

Could you perhaps share the code that isn’t working and the link to the screen you’re on so I could take a look?