VarunRavichander commited on
Commit
409ab2c
Β·
verified Β·
1 Parent(s): 974c2a3

Upload 2 files

Browse files
Files changed (2) hide show
  1. graph.py +203 -0
  2. requirements.txt +4 -0
graph.py ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import io
5
+
6
+ # Page configuration
7
+ st.set_page_config(
8
+ page_title="Excel Graph Generator",
9
+ page_icon="πŸ“ˆ",
10
+ layout="wide"
11
+ )
12
+
13
+ # Style input fields with black text and Times New Roman
14
+ st.markdown("""
15
+ <style>
16
+ * {
17
+ font-family: 'Times New Roman', Times, serif !important;
18
+ }
19
+ .stTextInput input {
20
+ color: black !important;
21
+ font-family: 'Times New Roman', Times, serif !important;
22
+ }
23
+ .stSelectbox select {
24
+ color: black !important;
25
+ font-family: 'Times New Roman', Times, serif !important;
26
+ }
27
+ .stMultiSelect select {
28
+ color: black !important;
29
+ font-family: 'Times New Roman', Times, serif !important;
30
+ }
31
+ </style>
32
+ """, unsafe_allow_html=True)
33
+
34
+ # Title and description
35
+ st.title('πŸ“Š Excel Graph Generator')
36
+ st.write('Upload your Excel file and create customized graphs with ease!')
37
+
38
+ # File upload
39
+ uploaded_file = st.file_uploader("Upload Excel File", type=['xlsx', 'xls'])
40
+
41
+ if uploaded_file:
42
+ # Read Excel file
43
+ df = pd.read_excel(uploaded_file)
44
+
45
+ # Show data preview
46
+ st.subheader("Data Preview")
47
+ st.dataframe(df.head())
48
+
49
+ # Column selection
50
+ st.subheader("Select Data for Plotting")
51
+ x_column = st.selectbox("Select X-axis column (Date)", df.columns)
52
+ y_columns = st.multiselect("Select Y-axis column(s)", [col for col in df.columns if col != x_column])
53
+
54
+ if y_columns:
55
+ # Graph customization
56
+ st.subheader("Customize Your Graph")
57
+
58
+ # Basic settings
59
+ plot_title = st.text_input("Enter Plot Title", "My Custom Graph")
60
+ x_axis_label = st.text_input("X-axis Label", x_column)
61
+ y_axis_label = st.text_input("Y-axis Label", "Values")
62
+
63
+ # Legend position controls
64
+ st.subheader("Legend Position Control")
65
+ col1, col2 = st.columns(2)
66
+ with col1:
67
+ legend_x = st.slider("Legend X Position", -0.5, 2.0, 1.05, 0.05)
68
+ with col2:
69
+ legend_y = st.slider("Legend Y Position", -0.5, 2.0, 1.0, 0.05)
70
+
71
+ # Legend customization
72
+ st.subheader("Customize Legend Names")
73
+ legend_names = {}
74
+ for col in y_columns:
75
+ legend_names[col] = st.text_input(f"Legend name for {col}", col)
76
+
77
+ # Define vibrant colors
78
+ vibrant_colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEEAD',
79
+ '#FF9F1C', '#E71D36', '#2EC4B6', '#011627']
80
+
81
+ # Generate plot
82
+ if st.button("Generate Graph"):
83
+ # Convert date column to datetime if it's not already
84
+ if pd.api.types.is_datetime64_any_dtype(df[x_column]) or pd.api.types.is_string_dtype(df[x_column]):
85
+ df[x_column] = pd.to_datetime(df[x_column]).dt.strftime('%d-%m-%Y') # Format dates as dd-mm-yyyy
86
+
87
+ # Create figure with vibrant colors
88
+ fig = px.line(df, x=x_column, y=y_columns,
89
+ color_discrete_sequence=vibrant_colors)
90
+
91
+ # Update legend names and hover template
92
+ for i, trace in enumerate(fig.data):
93
+ trace.name = legend_names[y_columns[i]]
94
+ trace.hovertemplate = f"{legend_names[y_columns[i]]}: %{{y}}<br>{x_axis_label}: %{{x}}<extra></extra>"
95
+
96
+ # Layout updates with Times New Roman and black text
97
+ fig.update_layout(
98
+ title=dict(
99
+ text=plot_title,
100
+ x=0.5,
101
+ xanchor='center',
102
+ yanchor='top',
103
+ font=dict(family="Times New Roman", color="black")
104
+ ),
105
+ showlegend=True,
106
+ legend=dict(
107
+ orientation="v",
108
+ yanchor="top",
109
+ y=legend_y,
110
+ xanchor="right",
111
+ x=legend_x,
112
+ bgcolor="white",
113
+ bordercolor="Black",
114
+ borderwidth=1,
115
+ font=dict(family="Times New Roman", color="black"),
116
+ title=dict(text="")
117
+ ),
118
+ hovermode='x unified',
119
+ plot_bgcolor='white',
120
+ paper_bgcolor='white',
121
+ xaxis=dict(
122
+ showgrid=True,
123
+ gridwidth=1,
124
+ gridcolor='LightGray',
125
+ showline=True,
126
+ linewidth=1,
127
+ linecolor='black',
128
+ mirror=True,
129
+ tickangle=-90, # Vertical text
130
+ title_text=x_axis_label,
131
+ title_font=dict(family="Times New Roman", color="black"),
132
+ tickfont=dict(family="Times New Roman", color="black", size=10),
133
+ type='category' # This ensures dates are treated as categories
134
+ ),
135
+ yaxis=dict(
136
+ showgrid=True,
137
+ gridwidth=1,
138
+ gridcolor='LightGray',
139
+ showline=True,
140
+ linewidth=1,
141
+ linecolor='black',
142
+ mirror=True,
143
+ title_text=y_axis_label,
144
+ title_font=dict(family="Times New Roman", color="black"),
145
+ tickfont=dict(family="Times New Roman", color="black")
146
+ ),
147
+ margin=dict(l=80, r=150, t=100, b=100),
148
+ width=900,
149
+ height=600,
150
+ shapes=[
151
+ dict(
152
+ type='rect',
153
+ xref='paper',
154
+ yref='paper',
155
+ x0=0,
156
+ y0=0,
157
+ x1=1,
158
+ y1=1,
159
+ line=dict(
160
+ color='black',
161
+ width=2,
162
+ )
163
+ )
164
+ ],
165
+ font=dict(family="Times New Roman")
166
+ )
167
+
168
+ # Display plot
169
+ st.plotly_chart(fig, use_container_width=True)
170
+
171
+ # Download options
172
+ buffer = io.StringIO()
173
+ fig.write_html(buffer)
174
+ st.download_button(
175
+ label="πŸ“Š Download Plot",
176
+ data=buffer.getvalue(),
177
+ file_name="plot.html",
178
+ mime="text/html"
179
+ )
180
+
181
+ # Footer
182
+ st.markdown("---")
183
+ st.markdown("""
184
+ ### πŸ“ Features:
185
+ - Excel file upload and preview
186
+ - Times New Roman font throughout
187
+ - Black text for all elements
188
+ - Clean legend display with custom names
189
+ - Customizable plot title, axes labels, and legend names
190
+ - Vibrant color schemes
191
+ - Interactive legend positioning with precise controls
192
+ - Interactive plot with hover details
193
+ - Download options in HTML format
194
+ """
195
+ """
196
+ ### πŸ“ For Support And Assistance:
197
+
198
+ Contact:
199
+ - Harshitha Gunnam
200
+ gunnamharshitha2@gmail.com
201
+ - Varun Ravichander
202
+ varunravichander2007@gmail.com
203
+ """)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.29.0
2
+ pandas==2.1.4
3
+ plotly==5.18.0
4
+ openpyxl==3.1.2