Spaces:
Build error
Build error
Commit
·
48664e3
1
Parent(s):
09447d8
update figure dimensions
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import seaborn as sns
|
|
| 5 |
from matplotlib import pyplot as plt
|
| 6 |
|
| 7 |
sns.set_style(style="darkgrid")
|
| 8 |
-
sns.set_context(context="notebook", font_scale=
|
| 9 |
|
| 10 |
MAX_NOISE = 20
|
| 11 |
DEFAULT_NOISE = 6
|
|
@@ -33,7 +33,7 @@ def generate_equation(process_params):
|
|
| 33 |
# Substitute parameter values into the expression
|
| 34 |
polynomial_with_values = polynomial_expression.subs(parameters)
|
| 35 |
latex_representation = sp.latex(polynomial_with_values)
|
| 36 |
-
return fr"$${latex_representation}$$"
|
| 37 |
|
| 38 |
|
| 39 |
def true_process(x, process_params):
|
|
@@ -72,33 +72,34 @@ def make_plot(
|
|
| 72 |
|
| 73 |
x, x_dense, y, y_dense, y_noisy = generate_data(num_points, noise_level, process_params)
|
| 74 |
|
| 75 |
-
fig = plt.figure(
|
| 76 |
if show_true_process:
|
| 77 |
plt.plot(
|
| 78 |
x_dense, y_dense, "-", color="#363A4F",
|
| 79 |
label="True Process",
|
|
|
|
| 80 |
)
|
| 81 |
if show_added_noise:
|
| 82 |
plt.vlines(
|
| 83 |
x, y, y_noisy, color="#556D9A",
|
| 84 |
linestyles="dashed",
|
| 85 |
alpha=0.75,
|
| 86 |
-
lw=1
|
| 87 |
label="Added Noise",
|
| 88 |
)
|
| 89 |
if show_original_points:
|
| 90 |
plt.plot(
|
| 91 |
x, y, "-o", color="none",
|
| 92 |
-
ms=
|
| 93 |
markerfacecolor="white",
|
| 94 |
markeredgecolor="#556D9A",
|
| 95 |
-
markeredgewidth=1.
|
| 96 |
label="Original Points",
|
| 97 |
)
|
| 98 |
if show_noisy_points:
|
| 99 |
plt.plot(
|
| 100 |
x, y_noisy, "-o", color="none",
|
| 101 |
-
ms=
|
| 102 |
markerfacecolor="#556D9A",
|
| 103 |
markeredgecolor="none",
|
| 104 |
markeredgewidth=1.5,
|
|
@@ -106,9 +107,9 @@ def make_plot(
|
|
| 106 |
label="Noisy Points",
|
| 107 |
)
|
| 108 |
|
| 109 |
-
plt.xlabel("\
|
| 110 |
-
plt.ylabel("\
|
| 111 |
-
plt.legend(fontsize=
|
| 112 |
plt.tight_layout()
|
| 113 |
plt.show()
|
| 114 |
return fig
|
|
@@ -155,7 +156,7 @@ with gr.Blocks() as demo:
|
|
| 155 |
show_params.append(gr.Checkbox(label="Show Added Noise", value=True))
|
| 156 |
show_params.append(gr.Checkbox(label="Show Noisy Points", value=True))
|
| 157 |
|
| 158 |
-
scatter_plot = gr.Plot(
|
| 159 |
|
| 160 |
num_points.change(fn=make_plot, inputs=[num_points, noise_level, process_params, *show_params], outputs=scatter_plot)
|
| 161 |
noise_level.change(fn=make_plot, inputs=[num_points, noise_level, process_params, *show_params], outputs=scatter_plot)
|
|
|
|
| 5 |
from matplotlib import pyplot as plt
|
| 6 |
|
| 7 |
sns.set_style(style="darkgrid")
|
| 8 |
+
sns.set_context(context="notebook", font_scale=0.6)
|
| 9 |
|
| 10 |
MAX_NOISE = 20
|
| 11 |
DEFAULT_NOISE = 6
|
|
|
|
| 33 |
# Substitute parameter values into the expression
|
| 34 |
polynomial_with_values = polynomial_expression.subs(parameters)
|
| 35 |
latex_representation = sp.latex(polynomial_with_values)
|
| 36 |
+
return fr"Underlying process $${latex_representation}$$"
|
| 37 |
|
| 38 |
|
| 39 |
def true_process(x, process_params):
|
|
|
|
| 72 |
|
| 73 |
x, x_dense, y, y_dense, y_noisy = generate_data(num_points, noise_level, process_params)
|
| 74 |
|
| 75 |
+
fig = plt.figure(dpi=300)
|
| 76 |
if show_true_process:
|
| 77 |
plt.plot(
|
| 78 |
x_dense, y_dense, "-", color="#363A4F",
|
| 79 |
label="True Process",
|
| 80 |
+
lw=1.5,
|
| 81 |
)
|
| 82 |
if show_added_noise:
|
| 83 |
plt.vlines(
|
| 84 |
x, y, y_noisy, color="#556D9A",
|
| 85 |
linestyles="dashed",
|
| 86 |
alpha=0.75,
|
| 87 |
+
lw=1,
|
| 88 |
label="Added Noise",
|
| 89 |
)
|
| 90 |
if show_original_points:
|
| 91 |
plt.plot(
|
| 92 |
x, y, "-o", color="none",
|
| 93 |
+
ms=6,
|
| 94 |
markerfacecolor="white",
|
| 95 |
markeredgecolor="#556D9A",
|
| 96 |
+
markeredgewidth=1.2,
|
| 97 |
label="Original Points",
|
| 98 |
)
|
| 99 |
if show_noisy_points:
|
| 100 |
plt.plot(
|
| 101 |
x, y_noisy, "-o", color="none",
|
| 102 |
+
ms=6.5,
|
| 103 |
markerfacecolor="#556D9A",
|
| 104 |
markeredgecolor="none",
|
| 105 |
markeredgewidth=1.5,
|
|
|
|
| 107 |
label="Noisy Points",
|
| 108 |
)
|
| 109 |
|
| 110 |
+
plt.xlabel("\nx")
|
| 111 |
+
plt.ylabel("\ny")
|
| 112 |
+
plt.legend(fontsize=7.5)
|
| 113 |
plt.tight_layout()
|
| 114 |
plt.show()
|
| 115 |
return fig
|
|
|
|
| 156 |
show_params.append(gr.Checkbox(label="Show Added Noise", value=True))
|
| 157 |
show_params.append(gr.Checkbox(label="Show Noisy Points", value=True))
|
| 158 |
|
| 159 |
+
scatter_plot = gr.Plot()
|
| 160 |
|
| 161 |
num_points.change(fn=make_plot, inputs=[num_points, noise_level, process_params, *show_params], outputs=scatter_plot)
|
| 162 |
noise_level.change(fn=make_plot, inputs=[num_points, noise_level, process_params, *show_params], outputs=scatter_plot)
|