我有一个简单的因子图
import seaborn as sns
g = sns.factorplot("name", "miss_ratio", "policy", dodge=.2,
linestyles=["none", "none", "none", "none"], data=df[df["level"] == 2])
问题是x标签都在一起,使它们不可读。如何旋转文本以使标签可读?
我有一个简单的因子图
import seaborn as sns
g = sns.factorplot("name", "miss_ratio", "policy", dodge=.2,
linestyles=["none", "none", "none", "none"], data=df[df["level"] == 2])
问题是x标签都在一起,使它们不可读。如何旋转文本以使标签可读?
当前回答
对于一个海上出生的孩子来说。热图,你可以旋转这些(基于@Aman的回答)
pandas_frame = pd.DataFrame(data, index=names, columns=names)
heatmap = seaborn.heatmap(pandas_frame)
loc, labels = plt.xticks()
heatmap.set_xticklabels(labels, rotation=45)
heatmap.set_yticklabels(labels[::-1], rotation=45) # reversed order for y
其他回答
如果有人想知道如何为clustermap CorrGrids(给定海运示例的一部分):
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(context="paper", font="monospace")
# Load the datset of correlations between cortical brain networks
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
corrmat = df.corr()
# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(12, 9))
# Draw the heatmap using seaborn
g=sns.clustermap(corrmat, vmax=.8, square=True)
rotation = 90
for i, ax in enumerate(g.fig.axes): ## getting all axes of the fig object
ax.set_xticklabels(ax.get_xticklabels(), rotation = rotation)
g.fig.show()
这仍然是一个matplotlib对象。试试这个:
# <your code here>
locs, labels = plt.xticks()
plt.setp(labels, rotation=45)
可以使用matplotlib.pyplot.xticks实现这一点
import matplotlib.pyplot as plt
plt.xticks(rotation = 'vertical')
# Or use degrees explicitly
degrees = 70 # Adjust according to one's preferences/needs
plt.xticks(rotation=degrees)
这里有一个例子可以说明它是如何工作的。
如果标签的名字很长,可能很难正确。使用catplot对我来说很有效的解决方案是:
import matplotlib.pyplot as plt
fig = plt.gcf()
fig.autofmt_xdate()
对于一个海上出生的孩子来说。热图,你可以旋转这些(基于@Aman的回答)
pandas_frame = pd.DataFrame(data, index=names, columns=names)
heatmap = seaborn.heatmap(pandas_frame)
loc, labels = plt.xticks()
heatmap.set_xticklabels(labels, rotation=45)
heatmap.set_yticklabels(labels[::-1], rotation=45) # reversed order for y