title: Change word color using WordCloud in Python
body: <p>I am using WordCloud from Python to create my word cloud.
  Here is my text, named <code>tmp</code>,
  <code>
  contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact science science science science area area area die die groove groove line line nonlinearity nonlinearity damper damper press press symmetric symmetric soliton soliton cast publish node textured real deterministic car segment kinematics</code>. </p>
  
  <p>And my code for create the word cloud is shown as below:</p>
  
  <pre><code>wordcloud = WordCloud(background_color='white',max_font_size = 50).generate(tmp)
  plt.imshow(wordcloud)
  plt.axis('off')
  plt.show()
  </code></pre>
  
  <p>Here is the picture I got. It's really weird right?
  So my questions are : </p>
  
  <p>Firstly, why there are two <code>contact</code> in this picture?</p>
  
  <p>Secondly, how can I change the default color setting to use only one specific color for all these words, say <code>red</code> for all words? I Googled and found there is a parameter called <code>color_function</code> in <code>WordCloud</code>.  But I didn't get anything related to this.</p>
  
  <p><a href="https://i.stack.imgur.com/ITuqv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ITuqv.png" alt="the Picture I got"></a></p>
  
  <p>Any comments and suggestions would be welcomed!
  Many thanks in advance!!</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I just figured out for the second question.</p>
  
  <pre><code>#change the value in return to set the single color need, in hsl format.
  def grey_color_func(word, font_size, position,orientation,random_state=None, **kwargs):
      return("hsl(230,100%%, %d%%)" % np.random.randint(49,51))
  
  #create the wordcloud object
  wordcloud = WordCloud(background_color='white',max_font_size = 50).generate(tmp)
  
  #change the color setting
  wordcloud.recolor(color_func = grey_color_func)
  </code></pre>
  
  <p>Anyone knows the answer for the second question?</p>