2

Here is my code:

import matplotlib.pyplot as plt
import pandas as pd
from scipy.cluster import hierarchy as hier


df = pd.read_excel('some_symmetricmatrix.xlsx')

Z = hier.linkage(df, 'ward')            
hier.set_link_color_palette(['#d95f02','#7570b3'])

fig = plt.figure(figsize=(3, 6))
ax = fig.add_subplot(1,1,1)
ax.set_xlabel('Distance')

den = hier.dendrogram(
    Z,
    leaf_font_size=10., 
    orientation = 'left',
    above_threshold_color= '#1b9e77'
)

ax.tick_params(axis='x',top='off')


plt.savefig('somedendrogram.png', bbox_inches='tight', transparent = True, dpi = 300)
plt.close()

This give me an image like this: enter image description here

I would like to remove the borders (or axes) of the dendrogram, but I would like to keep the ticks and the labels. I've already tried 2 methods from the net: 1. add ax.axis('off') to the code 2. use this piece of code to turn the visibility of the axes off. Both of these give this: enter image description here

I tried to Google this, but I couldn't find anything. I hope you can help me. :)

Georgina
  • 95
  • 6

0 Answers0