Skip to content

Commit 2b6c539

Browse files
authored
update pyplot demos (#1574)
1 parent 452a406 commit 2b6c539

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

docs/library/graphing/other-charts/pyplot.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9999
class 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%",

docs/vars/base_vars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ app = rx.App()
215215

216216

217217
class State(rx.State):
218-
x: rx.Field[dict[str, list[int]]] = rx.field(\{})
218+
x: rx.Field[dict[str, list[int]]] = rx.field(default_factory=dict)
219219

220220

221221
@app.add_page

pcweb/components/docpage/navbar/typesense.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TypesenseSearchState(rx.State):
8585

8686
# State variables
8787
search_query: rx.Field[str] = rx.field("")
88-
search_results: rx.Field[list[dict]] = rx.field([])
88+
search_results: rx.Field[list[dict]] = rx.field(default_factory=list)
8989
is_searching: rx.Field[bool] = rx.field(False)
9090
_show_results: bool = False
9191
selected_filter: rx.Field[str] = rx.field("All")

pcweb/pages/gallery/sidebar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class TemplatesState(rx.State):
2323
query: rx.Field[str] = rx.field("")
24-
checked_tags: rx.Field[set[str]] = rx.field(set())
24+
checked_tags: rx.Field[set[str]] = rx.field(default_factory=set)
2525
page: rx.Field[int] = rx.field(1)
2626
total_pages: rx.Field[int] = rx.field(1)
2727

0 commit comments

Comments
 (0)