Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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 在Seaborn绘制山脊图有困难_Python_Pandas_Seaborn_Ridgeline Plot - Fatal编程技术网

Python 在Seaborn绘制山脊图有困难

Python 在Seaborn绘制山脊图有困难,python,pandas,seaborn,ridgeline-plot,Python,Pandas,Seaborn,Ridgeline Plot,我有一个数据帧hour\u dist,显示客户到达特定位置的时间 hour_dist.sample(5) Location Hour 88131 1233000000000000 21 111274 1233000000000000 0 81126 2991000000000000 23 104181 1232000000000000 22 55719 1232000000000000 15 我试图用Seab

我有一个数据帧hour\u dist,显示客户到达特定位置的时间

hour_dist.sample(5)

        Location            Hour
88131   1233000000000000    21
111274  1233000000000000    0
81126   2991000000000000    23
104181  1232000000000000    22
55719   1232000000000000    15
我试图用Seaborn绘制这些数据,以可视化山脊线图()

它应该基本上显示每个位置的小时分布。下面是它的一个示例:


对于hour_dist,我一直尝试在y轴上绘制位置,在x轴上绘制小时,但没有成功。

对于我来说,工作将
g
更改为
Location
x
更改为
hour
,但如果有许多唯一的
位置
值,则应该有许多带有真实数据的绘图:

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)})


# Initialize the FacetGrid object
pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
g = sns.FacetGrid(df, row="Location", hue="Location", aspect=15, height=.5, palette=pal)
如果需要按百分比绘制:

#df['pct'] = df['Location'].div(df.groupby('Hour')['Location'].transform('sum'))
#g = sns.FacetGrid(df, row="pct", hue="pct", aspect=15, height=.5, palette=pal)


# Draw the densities in a few steps
g.map(sns.kdeplot, "Hour", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
g.map(sns.kdeplot, "Hour", 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, "Hour")

# 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)

对于我来说,工作时间将
g
更改为
Location
x
更改为
Hour
,但如果有许多唯一的
Location
值,则应该有许多带有真实数据的绘图:

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)})


# Initialize the FacetGrid object
pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
g = sns.FacetGrid(df, row="Location", hue="Location", aspect=15, height=.5, palette=pal)
如果需要按百分比绘制:

#df['pct'] = df['Location'].div(df.groupby('Hour')['Location'].transform('sum'))
#g = sns.FacetGrid(df, row="pct", hue="pct", aspect=15, height=.5, palette=pal)


# Draw the densities in a few steps
g.map(sns.kdeplot, "Hour", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
g.map(sns.kdeplot, "Hour", 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, "Hour")

# 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)