title: How to add legend to Folium map created with GeoJson?
body: <p>How do I add a color legend to the colormap of a Folium choropleth map created using the <code>folium.GeoJson</code> method? </p>
  
  <p>I've tried adding <code>'caption='</code> to the colormap, but this generates an error: </p>
  
  <blockquote>
    <p>TypeError: unsupported operand type(s) for -: 'str' and 'str'</p>
  </blockquote>
  
  <p>Code follows below. It generates a correct choropleth if I remove <code>colormap.add_to(state_map)</code>, but there is no legend.  Likewise, including <code>"caption="</code> inside the colormap specifications does not display a legend.</p>
  
  <pre><code>import pandas
  import folium
  from branca.colormap import LinearColormap
  
  
  # Specify the US state map geo data from file
  state_geo = 'us-states.json'
  
  # Define list of lists of state date to convert into pandas data frame
  stateData = [
      ["AL", 1], ["AK", 2], ["AZ", 3], ["AR", 4], ["CA", 5], ["CO", 6], ["CT", 7], ["DE", 8], ["FL", 9], 
      ["GA", 1], ["HI", 2], ["ID", 3], ["IL", 4], ["IN", 5], ["IA", 1], ["KS", 2], ["KY", 3], ["LA", 4], 
      ["ME", 5], ["MD", 6], ["MA", 7], ["MI", 8], ["MN", 9], ["MS", 1], ["MO", 2], ["MT", 3], ["NE", 4], 
      ["NV", 5], ["NH", 6], ["NJ", 7], ["NM", 8], ["NY", 9], ["NC", 1], ["ND", 2], ["OH", 3], ["OK", 4], 
      ["OR", 3], ["PA", 4], ["RI", 6], ["SC", 6], ["SD", 2], ["TN", 8], ["TX", 8], ["UT", 8], ["VA", 5],
      ["VT", 5], ["WA", 6], ["WV", 7], ["WI", 8], ["WY", 9] 
      ]
  
  
  # Find largest state total in order to set maximum value for darkets color
  maxValue = 0
  for s in stateData:
      if s[1] &gt; maxValue:
          maxValue = s[1]
  
  #convert list of lists into pandas dataframe
  df_States = pandas.DataFrame(stateData, columns = ['State', 'Total']) 
  df_statesDict = df_States.set_index('State')['Total']
  
  #create color range for map, using the maximum state value found above
  colormap = LinearColormap(
      colors=['white', 'red'], 
      index=[0 - round(maxValue * .1), round(maxValue * .9)], 
      vmin=df_States.min(), 
      vmax=df_States.max(),
      caption="Species"
      )
  
  # Initialize the folium map
  state_map = folium.Map(location=[37, -100], zoom_start=4.6,)
  
  # Configure the chloropleth layer and add to map
  folium.GeoJson(
      state_geo,
      style_function=lambda feature: {
          'fillColor': colormap(df_statesDict[feature['id']]),
          'color': 'black',
          'weight': 1,
          'fillOpacity': 0.8,
      }
      ).add_to(state_map)
  
  #add caption to map
  colormap.add_to(state_map)
  
  # make the layer control box visible
  folium.LayerControl().add_to(state_map)
  
  # Save map to html
  state_map.save('testingChoropleth.html')
  </code></pre>