12

I'm trying to deploy an app developed using Dash which use some matplotlib functions. When I run locally the application, it runs smoothly and everything is okay, however, when I deploy it using the same code (I'm deploying using heroku) the matplotlib version that is installed (which is the current 2.2.3) no longer find the attrbute 'cm' to create a colormap.

import matplotlib
cmap = matplotlib.cm.get_cmap('Reds')

Actual Outcome

Logs of the heroku app

Matplotlib version

I'm using Windows 10, with matplotlib 2.2.3 locally and in the deploy and, locally, my Python version is 3.6.6.

Thank you!

Kind regards, Renan

4 Answers 4

17

You need to import matplotlib.cm for this to work.

import matplotlib.cm
cmap = matplotlib.cm.get_cmap('Reds')
0
8

I had the same problem, but previous answers did not help. In the end, for me it was a matplotlib version problem. Here is how I solved it:

pip install matplotlib==3.7.3

The reason is that this command is deprecated. If you want to use a more rescent version of matplotlib you can use:

import matplotlib
matplotlib.colormaps.get_cmap('prism')
2
  • Note that, since version 3.9, matplotlib.cm.get_cmap no longer supports the second argument lut to resample the colormap to lut entries. Use matplotlib.pyplot.get_cmap to get this original behaviour.
    – madoee
    Commented May 27 at 16:40
  • 1
    Thanks! Helped me out because I use an older, no longer maintained library that requires an older mpl version and because I had to use pip instead of Conda. The latter would have resolved the version dependency seamlessly in my case. If you can, I recommend using Conda to avoid headaches like these. Commented Jun 5 at 12:38
4

Try:

import matplotlib.pyplot as plt
cmap = plt.cm.get_cmap('Reds')
1
  • 1
    Thanks for the reply. However, when I tried to make this a different warning appeared in my app logs: ModuleNotFoundError: No module named '_tkinter' Commented Sep 10, 2018 at 16:53
0

None of the above answers worked for me. My matplotlib version is 3.9.0

This worked.

import matplotlib.pyplot as plt
cmap = plt.get_cmap('Reds')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.