Guided Project: Visualizing The Gender Gap In College Degrees - import matplotlib.get_backend()


I’m trying to save the plot I made by using “matplotlib.get_backend()”, but I don’t know how to import this. I thought I could do it by using “import” function, but it returns a syntax error. Does anyone know how to do this?

NameErrorTraceback (most recent call last)
in ()
—> 74 matplotlib.get_backend()
75 plt.savefig(‘gender_degrees.png’)

NameError: name ‘matplotlib’ is not definedBasics.ipynb (54.5 KB)

You don’t require matplotlib.get_backend() to save your plots.

You only need to import the standard package in the beginning -

import matplotlib.pyplot as plt

And then use


and that will save the figure for you.

If for any reason you do require get_backend(), then you will have to import matplotlib specifically.

import matplotlib

matplotlib.get_backend() will only really return the backend that is being utilized by matplotlib in the background (there are multiple of them, and not necessarily something we need to concern ourselves with as beginners usually). It doesn’t really have any relation to saving a particular image, but I might be mistaken.