Ridgeline/Joyplot 跨越移动范围

Ridgeline/Joyplot across a moving range

(使用 Python 3.0)以 0.25 为增量,我想计算和绘制指定范围内给定数据的 PDF,以便于可视化。

多亏了 SO 社区,个人图的计算已经完成,但我无法完全正确地在值范围内正确迭代算法。

数据:https://www.dropbox.com/s/y78pynq9onyw9iu/Data.csv?dl=0

到目前为止,我拥有的是标准化的玩具数据,看起来像散弹枪爆炸,其中一个目标区域在黑线之间被隔离,增量为 0.25:

import csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
from matplotlib import pyplot as plt
import seaborn as sns
Data=pd.read_csv("Data.csv")

g = sns.jointplot(x="x", y="y", data=Data)

bottom_lim = 0
top_lim = 0.25
temp = Data.loc[(Data.y>=bottom_lim)&(Data.y<top_lim)]
g.ax_joint.axhline(top_lim, c='k', lw=2)
g.ax_joint.axhline(bottom_lim, c='k', lw=2)

# we have to create a secondary y-axis to the joint-plot, otherwise the kde 
might be very small compared to the scale of the original y-axis
ax_joint_2 = g.ax_joint.twinx()
sns.kdeplot(temp.x, shade=True, color='red', ax=ax_joint_2, legend=False)
ax_joint_2.spines['right'].set_visible(False)
ax_joint_2.spines['top'].set_visible(False)
ax_joint_2.yaxis.set_visible(False)

现在我想做的是在每个 0.25 数据带中对这些数据进行 ridgeline/joyplot。

我尝试了各种 Seaborn 示例中的一些技术,但没有真正说明值的范围或范围作为 y 轴。结果,我正在努力将我编写的算法转换为工作代码。

我不知道这是否正是您要找的,但希望这能让您大致了解。我对python也知之甚少,所以这里有一些R:

library(tidyverse)
library(ggridges)
data = read_csv("https://www.dropbox.com/s/y78pynq9onyw9iu/Data.csv?dl=1")

data2 = data %>%
  mutate(breaks = cut(x, breaks = seq(-1,7,.5), labels = FALSE))

data2 %>%
  ggplot(aes(x=x,y=breaks)) +
  geom_density_ridges() +
  facet_grid(~breaks, scales = "free")

data2 %>%
  ggplot(aes(x=x,y=y)) +
  geom_point() +
  geom_density() +
  facet_grid(~breaks, scales = "free")

请原谅格式不正确的轴。