nom-mon-ir
nom-mon-ir

Reputation: 3918

Colors for pandas timeline graphs with many series

I am using pandas for graphing data for a cluster of nodes. I find that pandas is repeating color values for the different series, which makes them indistinguishable.

I tried giving custom color values like this and passed the my_colors to the colors field in plot:

  my_colors = []
  for node in nodes_list:
    my_colors.append(rand_color())

rand_color() is defined as follows:

  def rand_color():
    from random import randrange
    return "#%s" % "".join([hex(randrange(16, 255))[2:] for i in range(3)])

But here also I need to avoid color values that are too close to distinguish. I sometimes have as many as 60 nodes (series). Most probably a hard-coded list of color values would be best option?

Upvotes: 0

Views: 767

Answers (1)

Thorsten Kranz
Thorsten Kranz

Reputation: 12765

You can get a list of colors from any colormap defined in Matplotlib, and even custom colormaps, by:

>>> import matplotlib.pyplot as plt
>>> colors = plt.cm.Paired(np.linspace(0,1,60))

Plotting an example with these colors:

>>> plt.scatter( range(60), [0]*60, color=colors )
<matplotlib.collections.PathCollection object at 0x04ED2830>
>>> plt.axis("off")
(-10.0, 70.0, -0.0015, 0.0015)
>>> plt.show()

Colors

I found the "Paired" colormap to be especially useful for this kind of things, but you can use any other available or custom colormap.

Upvotes: 3

Related Questions