title: How to improve the label placement in scatter plot
body: <p>I use matplotlib to plot a scatter chart:</p>
  
  <p><img src="https://i.stack.imgur.com/Nllqp.png" alt="enter image description here"></p>
  
  <p>And label the bubble using a transparent box according to the tip at <a href="https://stackoverflow.com/questions/9074996/matplotlib-how-to-annotate-point-on-a-scatter-automatically-placed-arrow">matplotlib: how to annotate point on a scatter automatically placed arrow?</a></p>
  
  <p>Here is the code:</p>
  
  <pre><code>if show_annote:
      for i in range(len(x)):
          annote_text = annotes[i][0][0]  # STK_ID
          ax.annotate(annote_text, xy=(x[i], y[i]), xytext=(-10,3),
              textcoords='offset points', ha='center', va='bottom',
              bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.2),
              fontproperties=ANNOTE_FONT) 
  </code></pre>
  
  <p>and the resulting plot:
  <img src="https://i.stack.imgur.com/v5FET.png" alt="enter image description here"></p>
  
  <p>But there is still room for improvement to reduce overlap (for instance the label box offset is fixed as (-10,3)). Are there algorithms that can:</p>
  
  <ol>
  <li>dynamically change the offset of label box according to the crowdedness of its neighbourhood</li>
  <li>dynamically place the label box remotely and add an arrow line beween bubble and label box</li>
  <li>somewhat change the label orientation</li>
  <li>label_box overlapping bubble is better than label_box overlapping label_box?</li>
  </ol>
  
  <p>I just want to make the chart easy for human eyes to comprehand, so some overlap is OK, not as rigid a constraint as <a href="http://en.wikipedia.org/wiki/Automatic_label_placement" rel="noreferrer">http://en.wikipedia.org/wiki/Automatic_label_placement</a> suggests. And the bubble quantity within the chart is less than 150 most of the time.</p>
  
  <p>I find the so called <code>Force-based label placement</code> <a href="http://bl.ocks.org/MoritzStefaner/1377729" rel="noreferrer">http://bl.ocks.org/MoritzStefaner/1377729</a>  is quite interesting. I don't know if there is any python code/package available to implement the algorithm.</p>
  
  <p>I am not an academic guy and not looking for an optimum solution, and my python codes need to label many many charts, so the the speed/memory is in the scope of consideration.   </p>
  
  <p>I am looking for a quick and effective solution. Any help (code,algorithm,tips,thoughts) on this subject? Thanks. </p>