I am trying to create a linked marginal plot above the original plot, with the same x axis but with a different y axis.
I've seen that in plotly.express
package there are 4 options in which you can create marginal_x plot on a scatter fig, but they are all based on the same columns as x and y.
In my case, I have a date on my x-axis and rate of something on my y-axis, and I am trying to produce a histogram marginal distribution plot of the samples of which this rate is based on (located in samples column within the df).
I'm simplifying what I've tried without lessening any important details:
import pandas as pd
import plotly.express as px
df = pd.DataFrame(
{
"date": [pd.Timestamp("20200102"), pd.Timestamp("20200103")],
"rate": [0.88, 0.96],
"samples": [130, 1200])
}
)
fig = px.scatter(df, x='date', y='rate', marginal_x='histogram')
fig.show()
The documentation I based on: https://plotly.com/python/marginal-plots/
My desired result: Example:
The difference is that I use an aggregated df, so my count is just 1, instead of being the amount of samples.
Any ideas?
Thanks!