0

I have two temporal sequences, let's say tweets per time of the day, for two different categories. I would like to plot them as a joyplot with as x axis the time of the day and as height the number of tweets.

My code is:

from joypy import joyplot
import pandas as pd
import numpy as np
np.random.seed(0)
df = pd.DataFrame(index = range(24 * 2))
df['value'] = list([int(10 * aa) for aa in np.random.rand(24 * 2)])
df.loc[23 : 30, 'value'] = 0
df['hour'] = [aa for aa  in range(24)] * 2
df['cat'] = ['A'] * 24 + ['B'] * 24
joyplot(df, by = 'cat', column = 'hour')

so df.head(3) will return:

   value  hour cat
0      5     0   A
1      7     1   A
2      6     2   A

I am expecting to see the variations of value in hour but I do get two flat plots enter image description here

Plotting the two lines (to have an idea of the expected plot)

dfa = df[df.cat == 'A']
dfb = df[df.cat == 'B']
plt.figure()
plt.plot(dfa.hour, dfa.value)
plt.plot(dfb.hour, dfb.value)

I obtain: enter image description here

How should I fix this?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Stefano
  • 276
  • 1
  • 8
  • Just a typo. You're plotting the hour column (which is the same for both) not the values. Change to `joyplot(df, by = 'cat', column = 'value')` – bwc Dec 02 '19 at 18:04
  • mmm, in that case, I obtain values from 0 to 10 as horizontal axes and as vertical then I have something that looks to be related to the distribution of the value on the horizontal. My purpose is plotting both `value` for both the categories as functions of the same variable (that's why I choose `hour` as columns, that is indeed the same for both :) ) – Stefano Dec 02 '19 at 18:31
  • I think you're misunderstanding what a joyplot (aka ridgeplot) is. They are distributions of data, not smoothed line graphs - which sounds like what you want. You can represent the data you're after in a number of ways - overlapped and filled bar charts or line graphs. Additionally, you could smooth the data first to get the appearance of a joyplot via a line plot. – bwc Dec 02 '19 at 18:39
  • Thank you for the help. I think I should have given a better explanation of my problem/intention. The question was actually about how to use joyplot for a purpose for which it is not designed in origin. The thing I am interested in is the geometrical disposition of the "subplots" (plot for each category). I guess I may try to build a sort of false distribution of values (so, for example, if I have 5 tweets at 20, I can create a dataframe with 5 times the value 20), but I hoped there was a more straight forward way to do so. – Stefano Dec 02 '19 at 20:30

0 Answers0