ahsangahothi commited on
Commit
57c842c
·
verified ·
1 Parent(s): 58346a8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ # Function to draw the plot
6
+ def draw_plot(length, width):
7
+ fig, ax = plt.subplots(figsize=(8, 8))
8
+
9
+ # Plotting the plot as a rectangle
10
+ ax.plot([0, length], [0, 0], color="blue") # Bottom side
11
+ ax.plot([0, length], [width, width], color="blue") # Top side
12
+ ax.plot([0, 0], [0, width], color="blue") # Left side
13
+ ax.plot([length, length], [0, width], color="blue") # Right side
14
+
15
+ # Adding labels and title
16
+ ax.set_title(f"Plot: Length = {length} units, Width = {width} units")
17
+ ax.set_xlabel("Length (units)")
18
+ ax.set_ylabel("Width (units)")
19
+
20
+ # Set the limits
21
+ ax.set_xlim(0, length + 10)
22
+ ax.set_ylim(0, width + 10)
23
+
24
+ # Hide the axes for better visual
25
+ ax.axis('off')
26
+
27
+ return fig
28
+
29
+ # Streamlit interface
30
+ st.title("Plot Drawing App")
31
+
32
+ # User input for plot dimensions
33
+ length = st.number_input("Enter the Length of the Plot (in units)", min_value=1, max_value=1000, value=50)
34
+ width = st.number_input("Enter the Width of the Plot (in units)", min_value=1, max_value=1000, value=30)
35
+
36
+ # Draw the plot when inputs are provided
37
+ if length and width:
38
+ fig = draw_plot(length, width)
39
+
40
+ # Display the plot
41
+ st.pyplot(fig)
42
+
43
+ # Option to download the plot image
44
+ st.download_button(
45
+ label="Download Plot Image",
46
+ data=fig_to_bytes(fig),
47
+ file_name="plot_image.png",
48
+ mime="image/png"
49
+ )
50
+
51
+ # Convert the plot to bytes for download
52
+ def fig_to_bytes(fig):
53
+ import io
54
+ img_bytes = io.BytesIO()
55
+ fig.savefig(img_bytes, format="png")
56
+ img_bytes.seek(0)
57
+ return img_bytes.read()