-2

Is there a python library with a rainbow color function?

What I want is a function such that I give as input a number between 0. and 1. and it returns a color on the rainbow palette between red and violet. In this way, if the input is np.linspace(0.,1.,7) it will return the seven colors of the rainbow in order.

3sm1r
  • 520
  • 4
  • 19
  • 1
    You can probably write one that does what you want. See my answers to the questions [Range values to pseudocolor](https://stackoverflow.com/questions/10901085/range-values-to-pseudocolor) and [Calculate RGB value for a range of values to create heat map](https://stackoverflow.com/questions/20792445/calculate-rgb-value-for-a-range-of-values-to-create-heat-map) for examples. – martineau Oct 10 '19 at 18:52
  • @martineau T.Y. I was hoping for an already existing function (in mathematica it exists), but I can also try to make it manually as you suggest. – 3sm1r Oct 10 '19 at 19:00
  • 1
    3sm1r: I understand your question, however asking for recommendations is off-topic on this site — which is why suggested that you look at some related questions (and their answers). If you can't get your own function to work, then asking a question about that _would_ be something appropriate here. – martineau Oct 10 '19 at 19:05

2 Answers2

0

Use pystyle

import pystyle
from pystyle import Colors, Colorate

print(Colorate.Horizontal(Colors.rainbow, 'some rainbow text'))
-2

https://gist.github.com/kawanet/a880c83f06d6baf742e45ac9ac52af96

You can easily create a function that returns the value what you needed.