@@ -81,10 +81,10 @@ def create_plot(theme: str, plot_data: tuple, scale: list):
8181 fig, ax = plt.subplots(facecolor = bg_color)
8282 ax.set_facecolor(bg_color)
8383
84- for (x, y), color in zip (plot_data, [" #4e79a7" , " #f28e2b" , " #59a14f " ]):
84+ for (x, y), color in zip (plot_data, [" #4e79a7" , " #f28e2b" ]):
8585 ax.scatter(x, y, c = color, s = scale, label = color, alpha = 0.6 , edgecolors = " none" )
8686
87- ax.legend(facecolor = bg_color, edgecolor = ' none' , labelcolor = text_color)
87+ ax.legend(loc = " upper right " , facecolor = bg_color, edgecolor = ' none' , labelcolor = text_color)
8888 ax.grid(True , color = grid_color)
8989 ax.tick_params(colors = text_color)
9090 for spine in ax.spines.values():
@@ -97,17 +97,19 @@ def create_plot(theme: str, plot_data: tuple, scale: list):
9797 return fig
9898
9999class PyplotState (rx .State ):
100- num_points: int = 100
101- plot_data: tuple = tuple (np.random.rand(2 , 100 ) for _ in range (3 ))
102- scale: list = [random.uniform(0 , 100 ) for _ in range (100 )]
100+ num_points: int = 25
101+ plot_data: tuple = tuple (np.random.rand(2 , 25 ) for _ in range (2 ))
102+ scale: list = [random.uniform(0 , 100 ) for _ in range (25 )]
103103
104+ @rx.event (temporal = True , throttle = 500 )
104105 def randomize (self ):
105- self .plot_data = tuple (np.random.rand(2 , self .num_points) for _ in range (3 ))
106+ self .plot_data = tuple (np.random.rand(2 , self .num_points) for _ in range (2 ))
106107 self .scale = [random.uniform(0 , 100 ) for _ in range (self .num_points)]
107108
109+ @rx.event (temporal = True , throttle = 500 )
108110 def set_num_points (self , num_points : list[int | float ]):
109111 self .num_points = int (num_points[0 ])
110- self .randomize()
112+ yield PyplotState .randomize()
111113
112114 @rx.var
113115 def fig_light (self ) -> Figure:
@@ -134,9 +136,9 @@ def pyplot_example():
134136 ),
135137 rx.text(" Number of Points:" ),
136138 rx.slider(
137- default_value = 100 ,
139+ default_value = 25 ,
138140 min_ = 10 ,
139- max = 1000 ,
141+ max = 100 ,
140142 on_value_commit = PyplotState.set_num_points,
141143 ),
142144 width = " 100%" ,
0 commit comments