Home > Software engineering >  Why is matplotlib.cm.jet not recognized while importing matplotlib alone?
Why is matplotlib.cm.jet not recognized while importing matplotlib alone?

Time:03-11

I tried to get matplotlib.cm.jet using the code below:

import matplotlib
print(matplotlib.cm.jet)

Unfortunately, I got the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-ae42efdc0f9b> in <module>
----> 1 light = matplotlib.cm.jet

AttributeError: module 'matplotlib' has no attribute 'cm'

But, if I include import matplotlib.pyplot as plt, it works well!!!!

import matplotlib
import matplotlib.pyplot as plt
print(matplotlib.cm.jet)

The output:

<matplotlib.colors.LinearSegmentedColormap object at 0x00000136974123D0>

Why does it happen?

CodePudding user response:

As commented pretty well by Mr. T and BigBen, it is an issue due the version of the Matplotlib I am using (3.3.1, also reproduced in version 3.4.3).

(...) seemingly they forgot to include cm in the directory. – Mr. T

An update to version 3.5.1 solves the problem.

Thank you guys!

  • Related