@@ -48,7 +48,7 @@ def get_chart_image(fig):
48
48
def main():
49
49
# Create a chart:
50
50
fig, ax = plt.subplots()
51
- ax.plot([ 1, 2, 3, 4], [ 10, 11, 12, 13] )
51
+ ax.plot(( 1, 2, 3, 4), ( 10, 11, 12, 13) )
52
52
53
53
# Render the image bytes in the UI:
54
54
hd.image(get_chart_image(fig), width=20)
@@ -82,7 +82,7 @@ def main():
82
82
def main():
83
83
theme = hd.theme()
84
84
85
- line_data = ([ 1, 2, 3, 4], [ 10, 11, 12, 13] )
85
+ line_data = (( 1, 2, 3, 4), ( 10, 11, 12, 13) )
86
86
87
87
if theme.is_dark:
88
88
# Render the matplotlib chart in dark mode:
@@ -116,7 +116,7 @@ def main():
116
116
def chart():
117
117
theme = hd.theme()
118
118
119
- line_data = ([ 1, 2, 3, 4], [ 10, 11, 12, 13] )
119
+ line_data = (( 1, 2, 3, 4), ( 10, 11, 12, 13) )
120
120
121
121
if theme.is_dark:
122
122
with plt.style.context("dark_background"):
@@ -162,8 +162,11 @@ def main():
162
162
163
163
```py-nodemo
164
164
@hd.cached
165
- def chart(state ):
165
+ def chart():
166
166
theme = hd.theme()
167
+ state = hd.state(
168
+ line_data=((1, 2, 3, 4), (10, 11, 12, 13))
169
+ )
167
170
168
171
if theme.is_dark:
169
172
with plt.style.context("dark_background"):
@@ -175,15 +178,8 @@ def chart(state):
175
178
176
179
hd.image(get_chart_image(fig), width=20)
177
180
178
- def main():
179
- state = hd.state(
180
- line_data=([1, 2, 3, 4], [10, 11, 12, 13])
181
- )
182
-
183
- chart(state)
184
-
185
181
if hd.button("Update Chart").clicked:
186
- state.line_data = ([ 1, 2, 3, 4], [ 5, 20, 8, 10] )
182
+ state.line_data = (( 1, 2, 3, 4), ( 5, 20, 8, 10) )
187
183
```
188
184
189
185
In this example, we store the chart's line data in
0 commit comments