-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
87 lines (69 loc) · 2.99 KB
/
app.py
File metadata and controls
87 lines (69 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import streamlit as st
import plotly.graph_objects as go
import pandas as pd
import os
# Create folder for your thesis images
SAVE_FOLDER = "images"
if not os.path.exists(SAVE_FOLDER):
os.makedirs(SAVE_FOLDER)
st.set_page_config(page_title="Thesis Plotting Tool", layout="wide")
st.title("📊 Thesis Data Plotter")
st.write("Enter your research data and labels below. Use the sidebar to save.")
# --- 1. DATA INPUT SECTION ---
st.header("1. Input Your Data")
col_a, col_b, col_c = columns = st.columns(3)
with col_a:
x_label = st.text_input("X-Axis Name", "Time")
x_unit = st.text_input("X-Axis Unit", "s")
x_data_raw = st.text_area("X Values (Numbers separated by commas)", "1, 2, 3, 4, 5")
with col_b:
y_label = st.text_input("Y-Axis Name", "Intensity")
y_unit = st.text_input("Y-Axis Unit", "counts")
y_data_raw = st.text_area("Y Values (Numbers separated by commas)", "10, 25, 15, 35, 20")
with col_c:
z_label = st.text_input("Z-Axis Name (For 3D)", "Temperature")
z_unit = st.text_input("Z-Axis Unit (For 3D)", "K")
z_data_raw = st.text_area("Z Values (Numbers separated by commas)", "5, 5, 5, 5, 5")
# --- 2. PROCESS NUMBERS ---
try:
x_vals = [float(i.strip()) for i in x_data_raw.split(",")]
y_vals = [float(i.strip()) for i in y_data_raw.split(",")]
z_vals = [float(i.strip()) for i in z_data_raw.split(",")]
# Show a small table of the data
st.subheader("Data Preview")
df = pd.DataFrame({"X": x_vals, "Y": y_vals, "Z": z_vals})
st.dataframe(df.T) # .T makes it look like a row
except Exception as e:
st.error(f"Waiting for valid numbers... Error: {e}")
st.stop()
# --- 3. GRAPH SETTINGS (SIDEBAR) ---
st.sidebar.header("Graph Customization")
dim = st.sidebar.radio("Plot Dimension", ["2D", "3D"])
g_type = st.sidebar.selectbox("Graph Style", ["Line + Dots", "Dots Only", "Bar Chart"])
g_title = st.sidebar.text_input("Main Graph Title", "Research Analysis")
# Axis Formatting
full_x = f"{x_label} ({x_unit})" if x_unit else x_label
full_y = f"{y_label} ({y_unit})" if y_unit else y_label
full_z = f"{z_label} ({z_unit})" if z_unit else z_label
# --- 4. CREATE THE PLOT ---
fig = go.Figure()
mode = 'lines+markers' if g_type == "Line + Dots" else 'markers'
if dim == "2D":
if g_type == "Bar Chart":
fig.add_trace(go.Bar(x=x_vals, y=y_vals))
else:
fig.add_trace(go.Scatter(x=x_vals, y=y_vals, mode=mode))
fig.update_layout(xaxis_title=full_x, yaxis_title=full_y)
else:
fig.add_trace(go.Scatter3d(x=x_vals, y=y_vals, z=z_vals, mode=mode))
fig.update_layout(scene=dict(xaxis_title=full_x, yaxis_title=full_y, zaxis_title=full_z))
fig.update_layout(title=g_title, template="plotly_white")
# Display Graph
st.plotly_chart(fig, use_container_width=True)
# --- 5. EXPORT SECTION ---
st.sidebar.header("Export")
img_name = st.sidebar.text_input("Filename", "figure_1")
if st.sidebar.button("💾 Save"):
path = os.path.join(SAVE_FOLDER, f"{img_name}.png")
fig.write_image(path)
st.sidebar.success(f"Saved: {path}")