Skip to content

Commit fd66286

Browse files
committed
add "fix axis" option in simulation
1 parent 595122b commit fd66286

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

pylbm_ui/simulation.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self):
2323
self.fig.canvas.header_visible = False
2424
self.plot_type = None
2525
self.color_bar = None
26+
self.fix_ylim = False
2627
# plt.ion()
2728

2829
def plot(self, t, domain, field, data, transpose=True, properties=None):
@@ -63,11 +64,22 @@ def plot(self, t, domain, field, data, transpose=True, properties=None):
6364
marker=marker,
6465
markersize=markersize
6566
)
67+
ylim = None
68+
if 'set_ylim' in properties:
69+
ylim = properties['set_ylim']
70+
if ylim is not None:
71+
self.ax.set_ylim(
72+
ymin=float(ylim[0]),
73+
ymax=float(ylim[1]),
74+
auto=False
75+
)
76+
self.fix_ylim = True
6677
else:
6778
self.plot_type.set_ydata(data)
68-
69-
self.ax.relim()
70-
self.ax.autoscale_view()
79+
80+
if not self.fix_ylim:
81+
self.ax.relim()
82+
self.ax.autoscale_view()
7183

7284
if not properties:
7385
self.ax.set_xlabel('x')
@@ -256,9 +268,12 @@ def save_one_field(f):
256268

257269
h5.save()
258270

259-
def plot(self, fig, field):
271+
def plot(self, fig, field, properties=None):
260272
data = self.get_data(field)
261-
fig.plot(self.sol.t, self.sol.domain, field, data)
273+
fig.plot(
274+
self.sol.t, self.sol.domain, field, data,
275+
properties=properties
276+
)
262277

263278
def save_config(self, filename='simu_config.json'):
264279
from .json import save_simu_config

pylbm_ui/widgets/simulation.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def __init__(self, test_case_widget, lb_scheme_widget):
7777
list(lb_scheme_widget.get_case().equation.get_fields().keys())
7878
)
7979

80+
self.fix_axis = v.Switch(label='Fix axis', v_model=False)
81+
self.fix_axis_ymin = v.TextField(
82+
label='ymin', v_model='', class_="d-none"
83+
)
84+
self.fix_axis_ymax = v.TextField(
85+
label='ymax', v_model='', class_="d-none"
86+
)
87+
# self.fix_axis_ymin.hide()
88+
# self.fix_axis_ymax.hide()
89+
8090
self.menu = [
8191
self.simulation_name,
8292
self.simu_cfg,
@@ -92,6 +102,13 @@ def __init__(self, test_case_widget, lb_scheme_widget):
92102
self.save_fields.widget
93103
]),
94104
]),
105+
v.ExpansionPanel(children=[
106+
v.ExpansionPanelHeader(children=['Graphic options']),
107+
v.ExpansionPanelContent(children=[
108+
self.fix_axis,
109+
self.fix_axis_ymin, self.fix_axis_ymax
110+
]),
111+
]),
95112
], multiple=True, class_='pa-0')
96113
]
97114

@@ -146,6 +163,7 @@ def __init__(self, test_case_widget, lb_scheme_widget):
146163
self.result.observe(self.replot, 'v_model')
147164
self.simu_cfg.observe(self.load_simu_cfg, 'v_model')
148165
self.discret['nt'].observe(self.change_period_by_nt, 'v_model')
166+
self.fix_axis.observe(self.on_fix_axis_click, 'v_model')
149167

150168
test_case_widget.select_case.observe(self.stop_simulation, 'v_model')
151169
lb_scheme_widget.select_case.observe(self.stop_simulation, 'v_model')
@@ -247,9 +265,20 @@ async def run_simu(self):
247265
self.plot = Plot()
248266
self.iplot = 0
249267
self.plot_output.children = [self.plot.fig.canvas]
268+
if self.fix_axis.v_model:
269+
ymin = self.fix_axis_ymin.v_model
270+
ymax = self.fix_axis_ymax.v_model
271+
self.plot_options = {
272+
'set_ylim': [ymin, ymax]
273+
}
274+
else:
275+
self.plot_options = None
250276

251277
self.simu.save_data(self.result.v_model)
252-
self.simu.plot(self.plot, self.result.v_model)
278+
self.simu.plot(
279+
self.plot, self.result.v_model,
280+
properties=self.plot_options
281+
)
253282
self.plot_output.children[0].draw_idle()
254283

255284
ite_to_save = self.save_fields.get_save_time(
@@ -271,7 +300,10 @@ async def run_simu(self):
271300
if nite > self.period.value:
272301
nite = 1
273302
self.simu.save_data(self.result.v_model)
274-
self.simu.plot(self.plot, self.result.v_model)
303+
self.simu.plot(
304+
self.plot, self.result.v_model,
305+
properties=self.plot_options
306+
)
275307
self.plot_output.children[0].draw_idle()
276308
###### await asyncio.sleep(0.2)
277309

@@ -333,6 +365,17 @@ def on_pause_click(self, widget, event, data):
333365
"""
334366
self.pause.v_model = not self.pause.v_model
335367

368+
def on_fix_axis_click(self, change):
369+
"""
370+
fix or not the ylim axis when click
371+
"""
372+
if self.fix_axis.v_model:
373+
self.fix_axis_ymin.show()
374+
self.fix_axis_ymax.show()
375+
else:
376+
self.fix_axis_ymin.hide()
377+
self.fix_axis_ymax.hide()
378+
336379
def replot(self, change):
337380
"""
338381
Update the plot.

0 commit comments

Comments
 (0)