title: How to plot scipy.hierarchy.dendrogram using polar coordinates?
body: <p>I'm trying to adapt the following resources to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/20924085/python-conversion-between-coordinates">Python conversion between coordinates</a></p>
  
  <p><a href="https://matplotlib.org/gallery/pie_and_polar_charts/polar_scatter.html" rel="noreferrer">https://matplotlib.org/gallery/pie_and_polar_charts/polar_scatter.html</a></p>
  
  <p>I can't seem to get the coordinates to transfer the dendrogram shape over to polar coordinates.</p>
  
  <p>Does anyone know how to do this?  I know there is an implementation in networkx but that requires building a graph and then using pygraphviz backend to get the positions.</p>
  
  <p><strong>Is there a way to convert dendrogram cartesian coordinates to polar coordinates with <code>matplotlib</code> and <code>numpy</code>?</strong> </p>
  
  <pre><code>import requests
  from ast import literal_eval
  import matplotlib.pyplot as plt
  import numpy as np 
  
  def read_url(url):
      r = requests.get(url)
      return r.text
  
  def cartesian_to_polar(x, y):
      rho = np.sqrt(x**2 + y**2)
      phi = np.arctan2(y, x)
      return(rho, phi)
  
  def plot_dendrogram(icoord,dcoord,figsize, polar=False):
      if polar:
          icoord, dcoord = cartesian_to_polar(icoord, dcoord)
      with plt.style.context("seaborn-white"):
          fig = plt.figure(figsize=figsize)
          ax = fig.add_subplot(111, polar=polar)
          for xs, ys in zip(icoord, dcoord):
              ax.plot(xs,ys, color="black")
          ax.set_title(f"Polar= {polar}", fontsize=15)
  
  # Load the dendrogram data
  string_data = read_url("https://pastebin.com/raw/f953qgdr").replace("\r","").replace("\n","").replace("\u200b\u200b","")
  
  # Convert it to a dictionary (a subset of the output from scipy.hierarchy.dendrogram)
  dendrogram_data = literal_eval(string_data)
  icoord = np.asarray(dendrogram_data["icoord"], dtype=float)
  dcoord = np.asarray(dendrogram_data["dcoord"], dtype=float)
  
  # Plot the cartesian version
  plot_dendrogram(icoord,dcoord, figsize=(8,3), polar=False)
  
  # Plot the polar version
  plot_dendrogram(icoord,dcoord, figsize=(5,5), polar=True)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9oMSj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9oMSj.png" alt="enter image description here"></a></p>
  
  <p>I just tried this and it's closer but still not correct:</p>
  
  <pre><code>import matplotlib.transforms as mtransforms
  with plt.style.context("seaborn-white"):
      fig, ax = plt.subplots(figsize=(5,5))
      for xs, ys in zip(icoord, dcoord):
          ax.plot(xs,ys, color="black",transform=trans_offset)
  
      ax_polar = plt.subplot(111, projection='polar')
      trans_offset = mtransforms.offset_copy(ax_polar.transData, fig=fig)
      for xs, ys in zip(icoord, dcoord):
          ax_polar.plot(xs,ys, color="black",transform=trans_offset)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Y6BEE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Y6BEE.png" alt="enter image description here"></a></p>