0

Does anyone know how to add a reference lineplot into a kdeplot that represents the median for each x value.

I tried to smoothen it applying a convolution with a hamming filter but it doesn't look to good.

Oliver Prislan
  • 320
  • 4
  • 12
  • 1
    I don't think this question is particularly clear. The median of a numpy array can be obtained via `np.median()`. Is the problem the plotting of a vertical line at `x=np.median(data)`? – ImportanceOfBeingErnest Aug 14 '18 at 20:49
  • Thank you for assisting. I have a KDEplot (showing some density clouds) now I would like a curve that represents the median at each x coordinate (basically splitting a cloud along the most dense area) – Oliver Prislan Aug 15 '18 at 19:17
  • 1
    oh, so that's a 2D kdeplot? I would suggest you spend some more words than one sentence explaining the problem and desired outcome. Also if you provide some code sample, people might be more inclined to play around with it and provide an answer. – ImportanceOfBeingErnest Aug 15 '18 at 20:21

1 Answers1

0

Finally, I solved it by plotting

# create an aggregation ef
ef = df[['Temp','Power]].groupby('Temp').median().reset_index()

# smooth the aggregation with mean() - shift(- half window) is needed for alignment
ef['roll_med_power'] = ef['Power'].rolling(5).mean().shift(-2)

# finally close the gaps at beginning and end with unsmoothed data
ef['roll_med'][:2] = ef['Power'][:2]
ef['roll_med'][-2:] = ef['Power'][-2:]
Oliver Prislan
  • 320
  • 4
  • 12