计算山脊线图中每个山脊的样本大小

2024-03-28 13:08:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望我的样本大小的文字在每个脊为脊图下面(右上角可能)。有人试过乔伊普洛特吗

import joypy

range_P = [0,500,1000,1500,2000,2500,3000]
labels = [('RZ for PRP. \n('+str(range_P[i])+'-'+str(range_P[i]+500)+' mm)') for i in range(7)]

fig, axes = joypy.joyplot([RZS_P['RZ'][(RZS_P['PRP'] > range_P[i]) & (RZS_P['PRP'] <= range_P[i]+500)] for i in range(7)],
                          ylim='own', 
                          overlap = 0, 
                          bins = 20, 
                          figsize=(6,10), 
                          alpha = 0.6, 
                          labels = labels, 
                          color  ='#1f78b4'
                         )
plt.xlim(0,1000)

enter image description here


Tags: inimportforlabelsfigrangemm样本
1条回答
网友
1楼 · 发布于 2024-03-28 13:08:34

当joyplot绘制多个图形时,每个图形的轴是独立的。因此,您可以设置一个位置并用于循环

我无法复制您的代码,但使用了joyplot author's code。文本t1、t2、t3、t4设置在每个图形的右侧

1.从某处下载iris.csv

2.设置样本=[]

3.通过调整y_position = axes[i].get_ylim()[1] / 3.5设置轴[]的x和y。文本(x,y,…)如您所愿

import joypy
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import cm

iris = pd.read_csv("iris.csv")

sample = ['t1', 't2', 't3', 't4']

%matplotlib inline

fig, axes = joypy.joyplot(iris, ylim='own')

for i in range(len(sample)):
    y_position = axes[i].get_ylim()[1] / 3.5  # adjust with ylim for each plot
    axes[i].text(9, y_position, sample[i])

enter image description here

相关问题 更多 >