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!

Paul
  • 10,381
  • 13
  • 48
  • 86
TripleH
  • 447
  • 7
  • 16
  • Perhaps this will help: http://stackoverflow.com/questions/12236566/setting-different-color-for-each-series-in-scatter-plot-on-matplotlib – Jujunol Apr 16 '16 at 22:38
  • It works for me with Python 2.7 – arne.z Apr 16 '16 at 23:07
  • It works for me too (Python 2.7) – heltonbiker Apr 16 '16 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. – roadrunner66 Apr 16 '16 at 23:30
  • Thank you! Using 'cmap=plt.cm.hot' and 'camp = pt.cm.jet both' work – TripleH Apr 17 '16 at 00:26

1 Answers1

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.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252