Spaces:
Build error
Build error
Create Base6Example.py
Browse files- pages/Base6Example.py +59 -0
pages/Base6Example.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
|
| 5 |
+
def should_highlight_coordinate(num):
|
| 6 |
+
return any(digit in str(num) for digit in ['6', '7', '8', '9'])
|
| 7 |
+
|
| 8 |
+
def create_interactive_graph():
|
| 9 |
+
# Create a DataFrame for the grid
|
| 10 |
+
df = pd.DataFrame([(x, y) for x in range(56) for y in range(56)], columns=['x', 'y'])
|
| 11 |
+
df['combined'] = df['x'] * 100 + df['y']
|
| 12 |
+
df['highlight'] = df['combined'].apply(should_highlight_coordinate)
|
| 13 |
+
|
| 14 |
+
# Create the Plotly figure
|
| 15 |
+
fig = go.Figure()
|
| 16 |
+
|
| 17 |
+
# Add highlighted areas
|
| 18 |
+
highlighted_points = df[df['highlight']]
|
| 19 |
+
fig.add_trace(go.Scatter(
|
| 20 |
+
x=highlighted_points['x'],
|
| 21 |
+
y=highlighted_points['y'],
|
| 22 |
+
mode='markers',
|
| 23 |
+
marker=dict(color='rgba(0, 0, 0, 0.2)', size=5),
|
| 24 |
+
showlegend=False
|
| 25 |
+
))
|
| 26 |
+
|
| 27 |
+
# Add grid lines
|
| 28 |
+
for i in range(0, 56, 5):
|
| 29 |
+
fig.add_shape(type="line", x0=i, y0=0, x1=i, y1=55, line=dict(color="gray", width=0.5))
|
| 30 |
+
fig.add_shape(type="line", x0=0, y0=i, x1=55, y1=i, line=dict(color="gray", width=0.5))
|
| 31 |
+
|
| 32 |
+
# Customize the layout
|
| 33 |
+
fig.update_layout(
|
| 34 |
+
xaxis=dict(range=[0, 55], dtick=5, title="X"),
|
| 35 |
+
yaxis=dict(range=[0, 55], dtick=5, title="Y"),
|
| 36 |
+
width=700,
|
| 37 |
+
height=600,
|
| 38 |
+
title="2D Interactive Graph Base 6 With Hidden State in Red"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
return fig
|
| 42 |
+
|
| 43 |
+
def main():
|
| 44 |
+
st.set_page_config(page_title="Interactive 2D Graph", layout="wide")
|
| 45 |
+
|
| 46 |
+
st.title("2D Interactive Graph Base 6 With Hidden State in Red")
|
| 47 |
+
|
| 48 |
+
fig = create_interactive_graph()
|
| 49 |
+
|
| 50 |
+
# Display the graph
|
| 51 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 52 |
+
|
| 53 |
+
# Display coordinate information
|
| 54 |
+
st.markdown("### Coordinate Information")
|
| 55 |
+
st.markdown("Hover over the graph to see coordinate information.")
|
| 56 |
+
st.markdown("Coordinates containing 6, 7, 8, or 9 are highlighted.")
|
| 57 |
+
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
main()
|