Land at the top of the marine cluster map

I created a cluster map using seaborn.clustermap. I would like to draw / draw a horizontal line on top of the heat map, as in this figureenter image description here

I was just trying to use matplotlib like:

plt.plot([x1, x2], [y1, y2], 'k-', lw = 10)

but the line is not displayed. The object returned seaborn.clustermapdoes not have any properties similar to this question . How can I build a line?

Here is the code that generates a “random” cluster map similar to the one I posted:

import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import random 

data = np.random.random((50, 50))
df = pd.DataFrame(data)
row_colors = ["b" if random.random() > 0.2 else "r"  for i in range (0,50)]
cmap = sns.diverging_palette(133, 10, n=7, as_cmap=True)
result = sns.clustermap(df, row_colors=row_colors, col_cluster = False, cmap=cmap, linewidths = 0)
plt.plot([5, 30], [5, 5], 'k-', lw = 10)
plt.show()
+4
source share
1 answer

axes, , ClusterGrid.ax_heatmap. ax.plot() . ax.axhline().

import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import random 

data = np.random.random((50, 50))
df = pd.DataFrame(data)
row_colors = ["b" if random.random() > 0.2 else "r"  for i in range (0,50)]
cmap = sns.diverging_palette(133, 10, n=7, as_cmap=True)
result = sns.clustermap(df, row_colors=row_colors, col_cluster = False, cmap=cmap, linewidths = 0)
print dir(result)  # here is where you see that the ClusterGrid has several axes objects hiding in it
ax = result.ax_heatmap  # this is the important part
ax.plot([5, 30], [5, 5], 'k-', lw = 10)
plt.show()

enter image description here

+8

Source: https://habr.com/ru/post/1609645/


All Articles