python - 标签和绘图重叠
问题描述
是否有一种方法可以使该图不与脊图(seaborn)中的 y 轴长标签重叠。我正在使用示例 seaborn 的代码(稍作编辑)来理解我的意思。
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})
# Create the data
rs = np.random.RandomState(1979)
x = rs.randn(500)
names = ['15--Specialist COP',
'16--Specialist other fieldcrops',
'20--Specialist horticulture',
'35--Specialist wine',
'36--Specialist orchards - fruits',
'37--Specialist olives',
'38--Permanent crops combined',
'45--Specialist milk',
'48--Specialist sheep and goats',
'49--Specialist cattle']
# 'Specialist granivores',
# 'Mixed crops',
# 'Mixed livestock',
# 'Mixed crops and livestock']
g = np.tile(names, 50)
df = pd.DataFrame(dict(x=x, g=g))
# Initialize the FacetGrid object
pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
g = sns.FacetGrid(df, row="g", hue="g", aspect=15, height=.5, palette=pal)
# Draw the densities in a few steps
g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2)
g.map(plt.axhline, y=0, lw=2, clip_on=False)
# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
ax = plt.gca()
ax.text(0, .2, label, fontweight="bold", color=color,
ha="left", va="center", transform=ax.transAxes)
g.map(label, "x")
# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25)
# Remove axes details that don't play well with overlap
g.set_titles("")
g.set(yticks=[])
g.despine(bottom=True, left=True)
plt.show()
解决方案
推荐阅读
- java - 将 JScrollPane 中的选定项目移动到列表顶部并在 java 中显示剩余项目
- python - 在mac中将mitmdump作为后台进程执行
- php - 无法访问新创建的 wordpress 表
- okta - OKTA SCIM API 中不存在的用户更新请求的响应是什么?
- youtube - 使用 YouTube API 搜索频道返回错误结果
- javascript - 使用 Jquery 为多个 API 调用显示动画文本
- html - 如何在angular的打字稿文件中访问formarray值
- ruby - 如何重构一个简单的长 case 语句
- javascript - vuejs 列出禁用元素上的事件
- javascript - 反应路由器不渲染组件然后他有参数