使用 seaborn 对 pandas 数据框进行聚类 - 重叠标签
Clustering a pandas dataframe with seaborn - overlapping labels
我在 Mac OS 10.10.2,Python 2.7.11,Seaborn 0.6.0,pandas 0.17.1,matplotlib 1.5.0 .我是 运行 以下代码,用于使用 seaborn.clustermap
:
对数据帧进行分层聚类
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
L = []
for i in range(25):
L.append('longlonglabel' + str(i))
df.index = L
sns.clustermap(df)
plt.show()
哪个returns:
我对行侧的重叠标签有一些问题。根据提供的示例 here,默认行为应水平设置标签。这是一个错误吗?任何人都可以复制它吗?
水平设置标签的解决方法如下:
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
L = []
for i in range(25):
L.append('longlonglabel' + str(i))
df.index = L
cg = sns.clustermap(df)
# Iterate over the labels
for text in cg.ax_heatmap.get_yticklabels():
text.set_rotation('horizontal')
plt.show()
我在 Mac OS 10.10.2,Python 2.7.11,Seaborn 0.6.0,pandas 0.17.1,matplotlib 1.5.0 .我是 运行 以下代码,用于使用 seaborn.clustermap
:
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
L = []
for i in range(25):
L.append('longlonglabel' + str(i))
df.index = L
sns.clustermap(df)
plt.show()
哪个returns:
我对行侧的重叠标签有一些问题。根据提供的示例 here,默认行为应水平设置标签。这是一个错误吗?任何人都可以复制它吗?
水平设置标签的解决方法如下:
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
L = []
for i in range(25):
L.append('longlonglabel' + str(i))
df.index = L
cg = sns.clustermap(df)
# Iterate over the labels
for text in cg.ax_heatmap.get_yticklabels():
text.set_rotation('horizontal')
plt.show()