title: replicating R/ggplot2 colours in python
body: <p>This link has R code to replicate ggplot's colours: <a href="https://stackoverflow.com/questions/15726096/plotting-family-of-functions-with-qplot-without-duplicating-data">Plotting family of functions with qplot without duplicating data</a></p>
  
  <p>I have had a go at replicating the code in python - but the results are not right ...</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  import math
  import colorsys
  
  # function to return a list of hex colour strings
  def colorMaker(n=12, start=15.0/360.0, saturation=1.0, valight=0.65) :
      listOfColours = []
      for i in range(n) :
          hue = math.modf(float(i)/float(n) + start)[0]
          #(r,g,b) = colorsys.hsv_to_rgb(hue, saturation, valight)
          (r,g,b) = colorsys.hls_to_rgb(hue, valight, saturation)
          listOfColours.append( '#%02x%02x%02x' % (int(r*255), int(g*255), int(b*255)) )
      return listOfColours
  
  # made up data
  x = np.array(range(20))
  d = {}
  d['y1'] = pd.Series(x, index=x)
  d['y2'] = pd.Series(1.5*x + 1, index=x)
  d['y3'] = pd.Series(2*x + 2, index=x)
  df = pd.DataFrame(d)
  
  # plot example
  plt.figure(num=1, figsize=(10,5), dpi=100) # set default image size
  colours = colorMaker(n=3)
  df.plot(linewidth=2.0, color=colours)
  fig = plt.gcf()
  fig.savefig('test.png')
  </code></pre>
  
  <p>The result ...</p>
  
  <p><img src="https://i.stack.imgur.com/cjoLL.png" alt="enter image description here"></p>