Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 标签和打印重叠_Python_Plot_Seaborn_Ridgeline Plot - Fatal编程技术网

Python 标签和打印重叠

Python 标签和打印重叠,python,plot,seaborn,ridgeline-plot,Python,Plot,Seaborn,Ridgeline Plot,在山脊图(seaborn)中,是否有方法使该图不与y轴的长标签重叠。我使用示例seaborn(稍加编辑)的代码来理解我的意思 谢谢你的帮助。 您是否尝试在plt.show()之前添加plt.tight_layout()?问题是:您希望它看起来如何?小标签?变换标签?用另一种颜色在前面显示标签?对我来说,理想的解决方案是将绘图移到右侧,但如果不能这样做,则在绘图前面显示标签(另一种颜色),类似于g.set(yticks=[],xlim=(-5,None))? import numpy as np

在山脊图(seaborn)中,是否有方法使该图不与y轴的长标签重叠。我使用示例seaborn(稍加编辑)的代码来理解我的意思

谢谢你的帮助。


您是否尝试在plt.show()之前添加plt.tight_layout()?问题是:您希望它看起来如何?小标签?变换标签?用另一种颜色在前面显示标签?对我来说,理想的解决方案是将绘图移到右侧,但如果不能这样做,则在绘图前面显示标签(另一种颜色),类似于
g.set(yticks=[],xlim=(-5,None))
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()