0

I want my sample size text on each of the ridge for the ridge plot below (on top right possible). Has anyone tried it with joyplot.

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

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Ep1c1aN
  • 683
  • 9
  • 25
  • Do you already know sample size and want to put that as a text? – shimo Dec 27 '19 at 02:46
  • I want the text. So basically, I want to integrate the text into the code itself, somehow. – Ep1c1aN Dec 27 '19 at 03:01
  • Joyplot seems to be based on matplotlib. So how about put `plt.text(x, y, 'text') ` at the bottom? x and y are position. Add import matplotlib.pyplot as plt . – shimo Dec 27 '19 at 03:25
  • That would be a lot of work to do for a large dataset and quite a lot of manual work too. Do you happen to know a way to integrate that into the code (like the x and y of the `plt.text` and `df.count()` for sample size in the loop too) for each ridge? – Ep1c1aN Dec 27 '19 at 04:40
  • I have tried to put text with for loop. Please check out. – shimo Dec 27 '19 at 10:55

1 Answers1

0

When joyplot plot multiple graphs, axis of each graph is independent. So you can set one position and use for loop.

I could not reproduce your code but used joyplot author's code. Text t1, t2, t3, t4 are set right side of each graph.

1.Download iris.csv from somewhere.

2.Set sample = [].

3.Set x and y of axes[].text(x,y,..) as you like by adjustig y_position = axes[i].get_ylim()[1] / 3.5.

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

shimo
  • 2,156
  • 4
  • 17
  • 21
  • @shimo....Thanks for the workaround. The reason I was asking for something to be in the same loop as analysis because `ylim = 'own'`, so a constant `y` might not get symmetrical results for each ridge. But I think that's to be expected. – Ep1c1aN Dec 27 '19 at 19:24
  • I happen to have another smaller question. Do you know how to combine 2 ridge plots with a similar x-axis? Like in the question but different dataset, I want them to overlap. Something like https://www.machinelearningplus.com/plots/top-50-matplotlib-visualizations-the-master-plots-python/attachment/24_joyplot_joypy-min/. And is it possible to inverse the y-axis in these plots? – Ep1c1aN Dec 27 '19 at 21:52
  • Sorry, I missed ylim. I have edited so that in for loop ylim is changed using y_max. For second question, please read maplotlib and subplot docs [like this](https://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/subplots_demo.html) – shimo Dec 27 '19 at 23:35
  • Thanks shimo. What I was talking was not just a simple subplot, but something mentioned here by me 'https://stackoverflow.com/questions/59507923/combining-2-joyplots-with-same-x-axis'. Simple `matplotlib` commands are not working for me. – Ep1c1aN Dec 28 '19 at 03:44