cyrusyc commited on
Commit
89bc52a
1 Parent(s): d9ed521

update diatomics yaxis ranges

Browse files
serve/tasks/homonuclear-diatomics.py CHANGED
@@ -18,7 +18,7 @@ st.markdown("# Homonuclear diatomics")
18
  # button to toggle plots
19
  container = st.container(border=True)
20
  energy_plot = container.checkbox("Show energy curves", value=True)
21
- force_plot = container.checkbox("Show force curves", value=False)
22
 
23
  ncols = 2
24
 
@@ -43,10 +43,9 @@ for i, symbol in enumerate(chemical_symbols[1:]):
43
  if rows.empty:
44
  continue
45
 
46
- # fig = go.Figure()
47
  fig = make_subplots(specs=[[{"secondary_y": True}]])
48
 
49
- ylo = float("inf")
50
 
51
  for j, method in enumerate(rows["method"].unique()):
52
  row = rows[rows["method"] == method].iloc[0]
@@ -71,7 +70,7 @@ for i, symbol in enumerate(chemical_symbols[1:]):
71
  cs = CubicSpline(rs, es)
72
  ys = cs(xs)
73
 
74
- ylo = min(ylo, ys.min()*1.2, -1)
75
 
76
  fig.add_trace(
77
  go.Scatter(
@@ -90,6 +89,8 @@ for i, symbol in enumerate(chemical_symbols[1:]):
90
  cs = CubicSpline(rs, fs)
91
  ys = cs(xs)
92
 
 
 
93
  fig.add_trace(
94
  go.Scatter(
95
  x=xs, y=ys,
@@ -118,10 +119,30 @@ for i, symbol in enumerate(chemical_symbols[1:]):
118
 
119
  # Set y-axes titles
120
  if energy_plot:
121
- fig.update_yaxes(title_text="Energy [eV]", secondary_y=False)
 
 
 
 
 
 
 
 
 
122
 
123
  if force_plot:
124
- fig.update_yaxes(title_text="Force [eV/Å]", secondary_y=True)
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  # cols[i % ncols].title(f"{row['name']}")
127
  cols[i % ncols].plotly_chart(fig, use_container_width=True, height=250)
 
18
  # button to toggle plots
19
  container = st.container(border=True)
20
  energy_plot = container.checkbox("Show energy curves", value=True)
21
+ force_plot = container.checkbox("Show force curves", value=True)
22
 
23
  ncols = 2
24
 
 
43
  if rows.empty:
44
  continue
45
 
 
46
  fig = make_subplots(specs=[[{"secondary_y": True}]])
47
 
48
+ elo, flo = float("inf"), float("inf")
49
 
50
  for j, method in enumerate(rows["method"].unique()):
51
  row = rows[rows["method"] == method].iloc[0]
 
70
  cs = CubicSpline(rs, es)
71
  ys = cs(xs)
72
 
73
+ elo = min(elo, ys.min()*1.2, -1)
74
 
75
  fig.add_trace(
76
  go.Scatter(
 
89
  cs = CubicSpline(rs, fs)
90
  ys = cs(xs)
91
 
92
+ flo = min(flo, ys.min()*1.2)
93
+
94
  fig.add_trace(
95
  go.Scatter(
96
  x=xs, y=ys,
 
119
 
120
  # Set y-axes titles
121
  if energy_plot:
122
+
123
+ fig.update_layout(
124
+ yaxis=dict(
125
+ title=dict(text="Energy [eV]"),
126
+ side="left",
127
+ range=[elo, 2*(abs(elo))],
128
+ )
129
+ )
130
+
131
+ # fig.update_yaxes(title_text="Energy [eV]", secondary_y=False)
132
 
133
  if force_plot:
134
+
135
+ fig.update_layout(
136
+ yaxis2=dict(
137
+ title=dict(text="Force [eV/Å]"),
138
+ side="right",
139
+ range=[flo, 2*(abs(flo))],
140
+ overlaying="y",
141
+ tickmode="sync",
142
+ ),
143
+ )
144
+
145
+ # fig.update_yaxes(title_text="Force [eV/Å]", secondary_y=True)
146
 
147
  # cols[i % ncols].title(f"{row['name']}")
148
  cols[i % ncols].plotly_chart(fig, use_container_width=True, height=250)