2

I am working on scattering plot using matplotlib and just simply testing several sample codes, but cannot show colors. Only showing gray. For example:

import numpy as np import matplotlib.pyplot as plt x = np.random.rand(100) y = np.random.rand(100) t = np.arange(100) plt.scatter(x, y, c=t) plt.show() 

This is the exactly same as this previous question about scatterplots and color mapping. See the execution result:

Screenshot of results

What's wrong with my setup? I am using Jupyter python 3.x version.

Thanks!

5
  • Perhaps this will help: stackoverflow.com/questions/12236566/… Commented Apr 16, 2016 at 22:38
  • It works for me with Python 2.7 Commented Apr 16, 2016 at 23:07
  • It works for me too (Python 2.7) Commented Apr 16, 2016 at 23:30
  • 1
    It shows colors to me. The question is why should it work? To set colors you should pass tuples of three. To set gray you should set a number between 0 and 1, but pass it as a string. So that command c=t is not really clear to me. Try cmap=plt.cm.hot inside the scatter command. It could be that you have cm.gray set earlier, and need to refresh the kernel. Commented Apr 16, 2016 at 23:30
  • Thank you! Using 'cmap=plt.cm.hot' and 'camp = pt.cm.jet both' work Commented Apr 17, 2016 at 0:26

1 Answer 1

5

You can try to force a specific colormap:

plt.scatter(x, y, c=t, cmap=plt.cm.jet) 

Also, as a bonus, you could colorize it more:

plt.scatter(x, y, c=t, cmap=plt.cm.jet, s=30, linewidths=0, alpha=0.7) # "s" is for (marker)"size" 

I cannot properly "test" it because your original code works for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.