0

I am having a really weird issue with using the %matplotlib inline code in my jupyter notebook for plotting graphs using both pyplot and the pandas plotting function.

The problem is they show up without any axes, and basically just show the graph area without anything aside from data points.

I found adding:

import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)

reverse it, but I find it odd that should do that every time as the effect disappears as soon as I run %matplotlib inlinecommand.

an example could be

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(A,A)
plt.tight_layout()
plt.xlabel('here')
plt.show()

This would generate the graph below:

enter image description here

Weird enough if I uses the savefig it get plotted with the axis, if I uses the right-click -> new output -> save as figure, I also get the graph with the figures !! like this:

"same as above"

Can anyone help me understand what is wrong, which global setting did I mess up, and how do I revert it? (I don't remember messing around with any settings aside from some settings for pandas, but don't think they should have had an impact)

as mentioned running mpl.rcParams.update(mpl.rcParamsDefault) command does bring it back to normal until I run %matplotlib inline` again !!

Any help would be much appreciated.

Mr. T
  • 11,960
  • 10
  • 32
  • 54
Jes Dreier
  • 31
  • 2
  • 1
    Thank you @Mr.T, the first image is https://imgur.com/K4pvUKv the second image is https://imgur.com/CFDTvf8 But actually just uploading them to imgur made me realize what was going on, I'll make an answer below for people who is equally stupid as I (it had to do with the jupyter dark mode theme) – Jes Dreier Feb 12 '21 at 15:33

1 Answers1

3

Okay I am sorry I think I can answer the question myself now. With the helpfull @Mr. T asking for the imgur link made me realize what was going on. I had starting using the dark jupyter lab theme, and the graph would generate plots with transparent background, ie. the text and lines where there, but I just couldn't see them. The trick is to change the background color preferably globally, but that will be a task for tomorrow.

Jes Dreier
  • 31
  • 2
  • 1
    Self-answering FTW. – Mr. T Feb 12 '21 at 16:49
  • Post your solution please :) – till Kadabra Jul 29 '22 at 08:25
  • 1
    @tillKadabra Sorry for never really getting back to this. The quick fix was to set the facecolor to white instead of transparrent. To do this ones per notebook add the following command ```import matplotlib.pyplot as plt plt.rcParams['axes.facecolor'] = 'black' ``` for more details on face colors see this thread: https://stackoverflow.com/questions/14088687/how-to-change-plot-background-color. The tricky part was to change it globally, and there is a settings file which I don't remember what is called, google will likely help. – Jes Dreier Aug 15 '22 at 11:28