Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,7 @@ import plotly.express as px
|
|
5 |
import plotly.graph_objects as go
|
6 |
from scipy.stats import norm
|
7 |
|
8 |
-
def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3'):
|
9 |
-
|
10 |
if plot_type == "Scatter":
|
11 |
fig = go.Figure()
|
12 |
|
@@ -26,7 +25,9 @@ def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colo
|
|
26 |
title=title,
|
27 |
xaxis_title="Percentage",
|
28 |
yaxis_title="Category",
|
29 |
-
yaxis={'categoryorder': 'array', 'categoryarray': sorted_data.index}
|
|
|
|
|
30 |
)
|
31 |
|
32 |
elif plot_type == "Heatmap":
|
@@ -51,7 +52,9 @@ def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colo
|
|
51 |
xaxis_title=xlabel,
|
52 |
yaxis_title=ylabel,
|
53 |
legend_title=legend_title,
|
54 |
-
template="plotly_white"
|
|
|
|
|
55 |
)
|
56 |
|
57 |
elif plot_type == "Bar":
|
@@ -63,8 +66,6 @@ def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colo
|
|
63 |
name=col
|
64 |
))
|
65 |
|
66 |
-
fig.update_layout(barmode='group')
|
67 |
-
|
68 |
fig.update_layout(
|
69 |
title={
|
70 |
'text': title,
|
@@ -76,17 +77,17 @@ def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colo
|
|
76 |
xaxis_title=xlabel,
|
77 |
yaxis_title=ylabel,
|
78 |
legend_title=legend_title,
|
79 |
-
template="plotly_white"
|
|
|
|
|
|
|
80 |
)
|
81 |
|
82 |
else:
|
83 |
-
raise ValueError("Invalid plot_type. Supported types are 'Heatmap' and 'Bar'.")
|
84 |
-
|
85 |
|
86 |
return fig
|
87 |
|
88 |
-
|
89 |
-
|
90 |
def is_matching_pattern(column, prefix):
|
91 |
if not column.startswith(prefix + '_'):
|
92 |
return False
|
@@ -378,7 +379,8 @@ if main_option == "Tabulation":
|
|
378 |
st.subheader("Frequency Table")
|
379 |
st.dataframe(frequency_df)
|
380 |
|
381 |
-
|
|
|
382 |
st.plotly_chart(fig, use_container_width=True)
|
383 |
|
384 |
elif type1 == "Single answer" and type2 == "Multiple answer":
|
@@ -391,7 +393,7 @@ if main_option == "Tabulation":
|
|
391 |
st.subheader("Frequency Table")
|
392 |
st.dataframe(frequency_df)
|
393 |
|
394 |
-
fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot')
|
395 |
st.plotly_chart(fig, use_container_width=True)
|
396 |
|
397 |
else:
|
@@ -408,7 +410,7 @@ if main_option == "Tabulation":
|
|
408 |
st.subheader("Frequency Table")
|
409 |
st.dataframe(frequency_df)
|
410 |
|
411 |
-
fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot')
|
412 |
st.plotly_chart(fig, use_container_width=True)
|
413 |
|
414 |
else:
|
|
|
5 |
import plotly.graph_objects as go
|
6 |
from scipy.stats import norm
|
7 |
|
8 |
+
def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3', width=800, height=600):
|
|
|
9 |
if plot_type == "Scatter":
|
10 |
fig = go.Figure()
|
11 |
|
|
|
25 |
title=title,
|
26 |
xaxis_title="Percentage",
|
27 |
yaxis_title="Category",
|
28 |
+
yaxis={'categoryorder': 'array', 'categoryarray': sorted_data.index},
|
29 |
+
width=width,
|
30 |
+
height=height
|
31 |
)
|
32 |
|
33 |
elif plot_type == "Heatmap":
|
|
|
52 |
xaxis_title=xlabel,
|
53 |
yaxis_title=ylabel,
|
54 |
legend_title=legend_title,
|
55 |
+
template="plotly_white",
|
56 |
+
width=width,
|
57 |
+
height=height
|
58 |
)
|
59 |
|
60 |
elif plot_type == "Bar":
|
|
|
66 |
name=col
|
67 |
))
|
68 |
|
|
|
|
|
69 |
fig.update_layout(
|
70 |
title={
|
71 |
'text': title,
|
|
|
77 |
xaxis_title=xlabel,
|
78 |
yaxis_title=ylabel,
|
79 |
legend_title=legend_title,
|
80 |
+
template="plotly_white",
|
81 |
+
barmode='group',
|
82 |
+
width=width,
|
83 |
+
height=height
|
84 |
)
|
85 |
|
86 |
else:
|
87 |
+
raise ValueError("Invalid plot_type. Supported types are 'Scatter', 'Heatmap', and 'Bar'.")
|
|
|
88 |
|
89 |
return fig
|
90 |
|
|
|
|
|
91 |
def is_matching_pattern(column, prefix):
|
92 |
if not column.startswith(prefix + '_'):
|
93 |
return False
|
|
|
379 |
st.subheader("Frequency Table")
|
380 |
st.dataframe(frequency_df)
|
381 |
|
382 |
+
row, col = df.shape
|
383 |
+
fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=len(col)*50, height=len(row)*50)
|
384 |
st.plotly_chart(fig, use_container_width=True)
|
385 |
|
386 |
elif type1 == "Single answer" and type2 == "Multiple answer":
|
|
|
393 |
st.subheader("Frequency Table")
|
394 |
st.dataframe(frequency_df)
|
395 |
|
396 |
+
fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=len(col)*50, height=len(row)*50)
|
397 |
st.plotly_chart(fig, use_container_width=True)
|
398 |
|
399 |
else:
|
|
|
410 |
st.subheader("Frequency Table")
|
411 |
st.dataframe(frequency_df)
|
412 |
|
413 |
+
fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=len(col)*50, height=len(row)*50)
|
414 |
st.plotly_chart(fig, use_container_width=True)
|
415 |
|
416 |
else:
|