|
3 | 3 | from dataclasses import asdict, dataclass |
4 | 4 |
|
5 | 5 | import pandas as pd |
| 6 | +import plotly.graph_objects as go |
6 | 7 | from nicegui import app, run, ui |
7 | 8 | from sklearn.cluster import DBSCAN, AgglomerativeClustering, KMeans |
8 | 9 | from sklearn.datasets import load_digits, load_iris |
@@ -83,6 +84,18 @@ class MapperConfig: |
83 | 84 | clustering_agglomerative_n_clusters: int = CLUSTERING_AGGLOMERATIVE_N_CLUSTERS |
84 | 85 |
|
85 | 86 |
|
| 87 | +def empty_figure(): |
| 88 | + fig = go.Figure() |
| 89 | + fig.update_layout( |
| 90 | + xaxis=dict(visible=False), |
| 91 | + yaxis=dict(visible=False), |
| 92 | + plot_bgcolor="rgba(0,0,0,0)", |
| 93 | + paper_bgcolor="rgba(0,0,0,0)", |
| 94 | + margin=dict(l=0, r=0, t=0, b=0), |
| 95 | + ) |
| 96 | + return fig |
| 97 | + |
| 98 | + |
86 | 99 | def fix_data(data): |
87 | 100 | df = pd.DataFrame(data) |
88 | 101 | df = df.select_dtypes(include="number") |
@@ -453,6 +466,9 @@ def _init_clustering_settings(self): |
453 | 466 |
|
454 | 467 | def _init_plot(self): |
455 | 468 | self.plot_container = ui.element("div").classes("w-full h-full") |
| 469 | + with self.plot_container: |
| 470 | + fig = empty_figure() |
| 471 | + self.draw_area = ui.plotly(fig).classes("w-full h-full") |
456 | 472 |
|
457 | 473 | def get_mapper_config(self): |
458 | 474 | return MapperConfig( |
@@ -575,10 +591,11 @@ async def async_run_mapper(self): |
575 | 591 | mapper_fig.layout.autosize = True |
576 | 592 | notification.message = "Done!" |
577 | 593 | notification.spinner = False |
| 594 | + self.draw_area.clear() |
578 | 595 | self.plot_container.clear() |
579 | 596 | with self.plot_container: |
580 | 597 | logger.info("Displaying Mapper plot.") |
581 | | - ui.plotly(mapper_fig).classes("w-full h-full") |
| 598 | + self.draw_area = ui.plotly(mapper_fig).classes("w-full h-full") |
582 | 599 | notification.dismiss() |
583 | 600 |
|
584 | 601 |
|
|
0 commit comments