gpt4 book ai didi

python - 跨越移动范围的山脊线/Joyplot

转载 作者:行者123 更新时间:2023-12-01 08:57:25 24 4
gpt4 key购买 nike

(使用 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)

enter image description here

现在我想做的是在每个 0.25 数据带上制作该数据的山脊线/欢乐图。

我尝试了各种 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")

请原谅格式错误的轴。

Image

关于python - 跨越移动范围的山脊线/Joyplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52705037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com