File size: 1,107 Bytes
52d1750 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import pandas as pd
import gradio as gr
import matplotlib.pyplot as plt
import seaborn as sns
from typing import Tuple
import plotly.express as px
def plot_kl_div_per_market(closed_markets: pd.DataFrame) -> gr.Plot:
# adding the total
all_markets = closed_markets.copy(deep=True)
all_markets["market_creator"] = "all"
# merging both dataframes
final_markets = pd.concat([closed_markets, all_markets], ignore_index=True)
final_markets = final_markets.sort_values(by="opening_datetime", ascending=True)
fig = px.box(
final_markets,
x="month_year_week",
y="kl_divergence",
color="market_creator",
color_discrete_sequence=["purple", "goldenrod", "darkgreen"],
category_orders={"market_creator": ["pearl", "quickstart", "all"]},
)
fig.update_traces(boxmean=True)
fig.update_layout(
xaxis_title="Markets closing Week",
yaxis_title="Kullback–Leibler divergence",
legend=dict(yanchor="top", y=0.5),
)
fig.update_xaxes(tickformat="%b %d\n%Y")
return gr.Plot(
value=fig,
)
|