Commit
·
d22f353
1
Parent(s):
f6984a9
new attempt to fix the graphs
Browse files- notebooks/invalid_markets.ipynb +24 -0
- tabs/invalid_markets.py +13 -12
notebooks/invalid_markets.ipynb
CHANGED
@@ -115,6 +115,30 @@
|
|
115 |
"plt.title(\"Distribution of daily invalid trades over time\")"
|
116 |
]
|
117 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
{
|
119 |
"cell_type": "markdown",
|
120 |
"metadata": {},
|
|
|
115 |
"plt.title(\"Distribution of daily invalid trades over time\")"
|
116 |
]
|
117 |
},
|
118 |
+
{
|
119 |
+
"cell_type": "code",
|
120 |
+
"execution_count": 15,
|
121 |
+
"metadata": {},
|
122 |
+
"outputs": [
|
123 |
+
{
|
124 |
+
"ename": "ModuleNotFoundError",
|
125 |
+
"evalue": "No module named 'plotly'",
|
126 |
+
"output_type": "error",
|
127 |
+
"traceback": [
|
128 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
129 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
130 |
+
"Cell \u001b[0;32mIn[15], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mplotly\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexpress\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpx\u001b[39;00m\n\u001b[1;32m 2\u001b[0m df \u001b[38;5;241m=\u001b[39m px\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mtips()\n\u001b[1;32m 3\u001b[0m fig \u001b[38;5;241m=\u001b[39m px\u001b[38;5;241m.\u001b[39mhistogram(df, x\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtotal_bill\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
131 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'plotly'"
|
132 |
+
]
|
133 |
+
}
|
134 |
+
],
|
135 |
+
"source": [
|
136 |
+
"import plotly.express as px\n",
|
137 |
+
"\n",
|
138 |
+
"fig = px.histogram(invalid_trades, x=\"creation_date\")\n",
|
139 |
+
"fig.show()"
|
140 |
+
]
|
141 |
+
},
|
142 |
{
|
143 |
"cell_type": "markdown",
|
144 |
"metadata": {},
|
tabs/invalid_markets.py
CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
from seaborn import FacetGrid
|
6 |
-
from matplotlib.axes import Axes
|
7 |
|
8 |
HEIGHT = 600
|
9 |
WIDTH = 1000
|
@@ -11,12 +10,12 @@ WIDTH = 1000
|
|
11 |
|
12 |
def plot_daily_dist_invalid_trades(invalid_trades: pd.DataFrame):
|
13 |
"""Function to paint the distribution of daily invalid trades, no matter which market"""
|
14 |
-
|
15 |
-
|
16 |
-
plt.
|
17 |
-
plt.
|
18 |
-
plt.
|
19 |
-
|
20 |
daily_trades_fig = plot2.get_figure()
|
21 |
return gr.Plot(value=daily_trades_fig)
|
22 |
|
@@ -36,7 +35,7 @@ def plot_daily_nr_invalid_markets(invalid_trades: pd.DataFrame):
|
|
36 |
return gr.LinePlot(
|
37 |
value=daily_invalid_markets,
|
38 |
x="creation_date",
|
39 |
-
y="
|
40 |
y_title="nr_markets",
|
41 |
interactive=True,
|
42 |
show_actions_button=True,
|
@@ -62,18 +61,20 @@ def plot_ratio_invalid_trades_per_market(invalid_trades: pd.DataFrame):
|
|
62 |
|
63 |
def plot_top_invalid_markets(invalid_trades: pd.DataFrame):
|
64 |
"""Function to paint the top markets with the highest number of invalid trades"""
|
65 |
-
top_invalid_markets =
|
|
|
|
|
|
|
|
|
66 |
top_invalid_markets.rename(columns={"count": "nr_invalid_trades"}, inplace=True)
|
67 |
return gr.BarPlot(
|
68 |
-
|
69 |
x="nr_invalid_trades",
|
70 |
y="title",
|
71 |
x_title="Nr_invalid_trades",
|
72 |
y_title="Market title",
|
73 |
-
show_label=True,
|
74 |
interactive=True,
|
75 |
show_actions_button=True,
|
76 |
-
value=top_invalid_markets,
|
77 |
tooltip=["title", "nr_invalid_trades"],
|
78 |
height=HEIGHT,
|
79 |
width=WIDTH,
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
from seaborn import FacetGrid
|
|
|
6 |
|
7 |
HEIGHT = 600
|
8 |
WIDTH = 1000
|
|
|
10 |
|
11 |
def plot_daily_dist_invalid_trades(invalid_trades: pd.DataFrame):
|
12 |
"""Function to paint the distribution of daily invalid trades, no matter which market"""
|
13 |
+
invalid_trades["creation_date"] = invalid_trades["creation_date"].astype(str)
|
14 |
+
plot2 = sns.histplot(data=invalid_trades, x="creation_date", kde=True)
|
15 |
+
# plt.title("Distribution of daily invalid trades over time")
|
16 |
+
# plt.xlabel("Creation date")
|
17 |
+
# plt.ylabel("Daily number of invalid trades")
|
18 |
+
# plt.xticks(rotation=45, ha="right")
|
19 |
daily_trades_fig = plot2.get_figure()
|
20 |
return gr.Plot(value=daily_trades_fig)
|
21 |
|
|
|
35 |
return gr.LinePlot(
|
36 |
value=daily_invalid_markets,
|
37 |
x="creation_date",
|
38 |
+
y="nr_markets",
|
39 |
y_title="nr_markets",
|
40 |
interactive=True,
|
41 |
show_actions_button=True,
|
|
|
61 |
|
62 |
def plot_top_invalid_markets(invalid_trades: pd.DataFrame):
|
63 |
"""Function to paint the top markets with the highest number of invalid trades"""
|
64 |
+
top_invalid_markets: pd.DataFrame = (
|
65 |
+
invalid_trades.title.value_counts().reset_index()
|
66 |
+
)
|
67 |
+
print(top_invalid_markets.head(5))
|
68 |
+
top_invalid_markets = top_invalid_markets.head(5)
|
69 |
top_invalid_markets.rename(columns={"count": "nr_invalid_trades"}, inplace=True)
|
70 |
return gr.BarPlot(
|
71 |
+
value=top_invalid_markets,
|
72 |
x="nr_invalid_trades",
|
73 |
y="title",
|
74 |
x_title="Nr_invalid_trades",
|
75 |
y_title="Market title",
|
|
|
76 |
interactive=True,
|
77 |
show_actions_button=True,
|
|
|
78 |
tooltip=["title", "nr_invalid_trades"],
|
79 |
height=HEIGHT,
|
80 |
width=WIDTH,
|