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

Hello,

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 ()
72 plt.show()
73
—> 74 matplotlib.get_backend()
75 plt.savefig(‘gender_degrees.png’)
76

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

plt.savefig(‘gender_degrees.png’)

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()

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.