cwadayi commited on
Commit
c8edb35
·
verified ·
1 Parent(s): 04f15f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -233,7 +233,7 @@ def _normalize_times(series: pd.Series) -> pd.Series:
233
 
234
  def render_line(df, col):
235
  times = _normalize_times(df["time"])
236
- fig, ax = plt.subplots(figsize=(6.5, 3.6))
237
  ax.plot(times, df[col], linewidth=1.6)
238
  ax.set_title(col, fontsize=12, pad=8)
239
  ax.set_xlabel("Time")
@@ -246,7 +246,7 @@ def render_line(df, col):
246
  def render_bar_or_dual(df, second_col, first_col, dual_axis):
247
  times = _normalize_times(df["time"])
248
  x = mdates.date2num(times.dt.to_pydatetime().tolist())
249
- fig, ax = plt.subplots(figsize=(6.5, 3.6))
250
  width = max(10, (times.astype("int64").diff().median() or 60) / 1e9 * 0.8) / 86400
251
  ax.bar(x, df[second_col], width=width, align="center", label=second_col)
252
  title = f"{second_col} (bar)"
@@ -270,7 +270,7 @@ def render_rolling(df, col, window=5):
270
  roll_col = f"{col}_rolling{window}"
271
  if roll_col not in df.columns:
272
  df[roll_col] = df[col].rolling(window=window, min_periods=1).mean()
273
- fig, ax = plt.subplots(figsize=(6.5, 3.6))
274
  ax.plot(times, df[roll_col], linewidth=1.6)
275
  ax.set_title(f"{col} rolling({window})", fontsize=12, pad=8)
276
  ax.set_xlabel("Time")
@@ -311,7 +311,7 @@ def render_gauge(df, col):
311
  else:
312
  arrow = 3
313
 
314
- fig, ax = plt.subplots(figsize=(6, 4))
315
 
316
  ang_range, mid_points = degree_range(N)
317
 
@@ -326,14 +326,14 @@ def render_gauge(df, col):
326
 
327
  for mid, lab in zip(mid_points, labels):
328
  ax.text(0.35 * np.cos(np.radians(mid)), 0.35 * np.sin(np.radians(mid)), lab,
329
- horizontalalignment='center', verticalalignment='center', fontsize=14,
330
  fontweight='bold', rotation=rot_text(mid))
331
 
332
  r = Rectangle((-0.4, -0.1), 0.8, 0.1, facecolor='w', lw=2)
333
  ax.add_patch(r)
334
 
335
  ax.text(0, -0.05, f"Latest {col}: {value:.2f}", horizontalalignment='center',
336
- verticalalignment='center', fontsize=14, fontweight='bold')
337
 
338
  pos = mid_points[abs(arrow - N)]
339
  ax.arrow(0, 0, 0.225 * np.cos(np.radians(pos)), 0.225 * np.sin(np.radians(pos)),
@@ -538,14 +538,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
538
  with gr.Tabs():
539
  with gr.Tab("圖表"):
540
  with gr.Row():
541
- plot1 = gr.Plot(label="1:Line")
542
- plot2 = gr.Plot(label="2Bar / Dual Axis")
 
 
543
  with gr.Row():
544
- plot3 = gr.Plot(label="3:Rolling Mean")
545
- plot4 = gr.Plot(label="4Gauge")
 
 
546
 
547
  with gr.Tab("地圖"):
548
- map_out = gr.HTML(label="4:Geo Map (Interactive + Legend + Heatmap)")
549
 
550
  with gr.Tab("JSON & 檔案"):
551
  json_box = gr.Code(label="grafanalib Dashboard JSON", language="json")
 
233
 
234
  def render_line(df, col):
235
  times = _normalize_times(df["time"])
236
+ fig, ax = plt.subplots(figsize=(6, 3))
237
  ax.plot(times, df[col], linewidth=1.6)
238
  ax.set_title(col, fontsize=12, pad=8)
239
  ax.set_xlabel("Time")
 
246
  def render_bar_or_dual(df, second_col, first_col, dual_axis):
247
  times = _normalize_times(df["time"])
248
  x = mdates.date2num(times.dt.to_pydatetime().tolist())
249
+ fig, ax = plt.subplots(figsize=(6, 3))
250
  width = max(10, (times.astype("int64").diff().median() or 60) / 1e9 * 0.8) / 86400
251
  ax.bar(x, df[second_col], width=width, align="center", label=second_col)
252
  title = f"{second_col} (bar)"
 
270
  roll_col = f"{col}_rolling{window}"
271
  if roll_col not in df.columns:
272
  df[roll_col] = df[col].rolling(window=window, min_periods=1).mean()
273
+ fig, ax = plt.subplots(figsize=(6, 3))
274
  ax.plot(times, df[roll_col], linewidth=1.6)
275
  ax.set_title(f"{col} rolling({window})", fontsize=12, pad=8)
276
  ax.set_xlabel("Time")
 
311
  else:
312
  arrow = 3
313
 
314
+ fig, ax = plt.subplots(figsize=(5, 3.5))
315
 
316
  ang_range, mid_points = degree_range(N)
317
 
 
326
 
327
  for mid, lab in zip(mid_points, labels):
328
  ax.text(0.35 * np.cos(np.radians(mid)), 0.35 * np.sin(np.radians(mid)), lab,
329
+ horizontalalignment='center', verticalalignment='center', fontsize=12,
330
  fontweight='bold', rotation=rot_text(mid))
331
 
332
  r = Rectangle((-0.4, -0.1), 0.8, 0.1, facecolor='w', lw=2)
333
  ax.add_patch(r)
334
 
335
  ax.text(0, -0.05, f"Latest {col}: {value:.2f}", horizontalalignment='center',
336
+ verticalalignment='center', fontsize=12, fontweight='bold')
337
 
338
  pos = mid_points[abs(arrow - N)]
339
  ax.arrow(0, 0, 0.225 * np.cos(np.radians(pos)), 0.225 * np.sin(np.radians(pos)),
 
538
  with gr.Tabs():
539
  with gr.Tab("圖表"):
540
  with gr.Row():
541
+ with gr.Column(scale=1):
542
+ plot1 = gr.Plot(label="1Line")
543
+ with gr.Column(scale=1):
544
+ plot2 = gr.Plot(label="2:Bar / Dual Axis")
545
  with gr.Row():
546
+ with gr.Column(scale=1):
547
+ plot3 = gr.Plot(label="3Rolling Mean")
548
+ with gr.Column(scale=1):
549
+ plot4 = gr.Plot(label="4:Gauge")
550
 
551
  with gr.Tab("地圖"):
552
+ map_out = gr.HTML(label="5:Geo Map (Interactive + Legend + Heatmap)")
553
 
554
  with gr.Tab("JSON & 檔案"):
555
  json_box = gr.Code(label="grafanalib Dashboard JSON", language="json")