1

I have been using joypy for plotting what are called ridgeline/joy plots. I want to divide my dataframe equally into several parts, and recursively making each one of them as joy plot and adding them altogether for the ease of visualisation. Without doing so I just get one very long plot which is difficult to view. I have tried using subplots and making a new joypy.joyplot within a for-loop, but no success :(

import joypy
import mplcursors
from matplotlib import cm
import matplotlib.pyplot as plt

data = pd.DataFrame(np.random.rand(180,7), columns=list('ABCDEFG'))

x_range = list(range(len(data)))
fig, axes = joypy.joyplot(data, kind="values", x_range=x_range, colormap=cm.Set2,
                         figsize=(100,10))
axes[-1].set_xticks(x_range);
mplcursors.cursor(hover=True)

fig.savefig('joyplot.png', bbox_inches='tight')

What I have tried:

import joypy
from matplotlib import cm
import matplotlib.pyplot as plt

f, a = plt.subplots(2, 1)
data = pd.DataFrame(np.random.rand(180,7), columns=list('ABCDEFG'))

for c, i in enumerate(range(0, len(data), 50)):
    x_range = list(range(i, i+50, 1))
    fig, axes = joypy.joyplot(data[i:i+50], kind="values", x_range=x_range, colormap=cm.Set2,
                             figsize=(100,10),
                             title="Emotion evolution over an interview")
    # I don't know what to do here so the current fig can be added as subplot..
    a[c].set_xticks(x_range);

fig.show()

Also, does anyone know how to make the plot interactive, as when my mouse hovers over the plot then the its value of the y-axis appears. mplcursors doesn't seem to work. Any help is appreciated! Thanks.

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Blue482
  • 2,926
  • 5
  • 29
  • 40
  • 1
    Your code is not runnable. How would you imagine someone to find out what "without success" means? – ImportanceOfBeingErnest Nov 16 '18 at 16:27
  • You're right. Sorry about that. I have edited the original question now. Thanks! – Blue482 Nov 16 '18 at 17:24
  • 1
    I don't think you can use subplots. Even if subplots were possible, they would still take exactly the same space in the figure, right? So what exactly would be the desired outcome? – ImportanceOfBeingErnest Nov 16 '18 at 17:39
  • I have edited the question again adding a for-loop that I am hoping for recursively adding the ridgeline plot as subplot to the overall figure. Basically I want to divide this long plot to several subplots, and display all of them one below another. – Blue482 Nov 16 '18 at 17:48
  • 1
    I think I understand what you are trying to do. But why? Where is the difference between having 6 curves below each other compared to having 2 times 3 curves below each other? Anyways, with `joypy` you cannot create subplots. So if you want to tell how the final plot is supposed to look like, one can probably provide a solution without the use of joypy. – ImportanceOfBeingErnest Nov 16 '18 at 17:59
  • Currently the code in the question generates a very long plot, which is difficult to view. If I have it divided to subplots and displayed one after another, it just makes it easier to view and I can get the whole picture displayed on the same screen w/o having moving the screen to the right all the time. Hope this makes sense. – Blue482 Nov 16 '18 at 18:21
  • I understand joypy outputs a figure therefore subplots cannot be used. But is there not any way to combine/append the figure generated by joypy into single figure recursively?? – Blue482 Nov 16 '18 at 18:22
  • 1
    No there isn't. Two options: (a) modify the joypy source code (b) don't use joypy. – ImportanceOfBeingErnest Nov 16 '18 at 18:26
  • Lol thanks for the concise and clear answer ! – Blue482 Nov 16 '18 at 18:35

0 Answers0