Spaces:
Build error
Build error
Upload app.py
Browse files37 unmodified lines3839404142434445464748495051525354555657585960616263646566676869707172737437 unmodified linestitle='Crop Coverage Over Time (Filtered)')# ---- Treemap: Crops by Land Use ----# Clean + aggregate datatreemap_data = (filtered.dropna(subset=['GenLU', 'crop_name']).copy())# Ensure strings, remove unicode issuestreemap_data['GenLU'] = treemap_data['GenLU'].astype(str).str.replace(r'[^a-zA-Z0-9\s/]', '', regex=True)treemap_data['crop_name'] = treemap_data['crop_name'].astype(str).str.replace(r'[^a-zA-Z0-9\s/]', '', regex=True)# Group by hierarchy and sum field countstreemap_data = (treemap_data.groupby(['GenLU', 'crop_name'], as_index=False).agg({'FBndID': 'count'}).rename(columns={'FBndID': 'field_count'}))# Create treemaptreemap = px.treemap(treemap_data,path=['GenLU', 'crop_name'],values='field_count',color='GenLU',title='Treemap: Dominant Crops by Land Use Category')# ---- Layout ----st.altair_chart(area_chart, use_container_width=True)st.plotly_chart(treemap, use_container_width=True)# ---- Discussion Section ----st.subheader("🧾 How to Use This Dashboard")37 unmodified lines3839404142434445464748495051525354555657585937 unmodified linestitle='Crop Coverage Over Time (Filtered)')# ---- Scatter Plot: Crop Coverage vs Rotation Diversity ----scatter = alt.Chart(filtered).mark_circle(size=60).encode(x=alt.X('year:O', title='Year'),y=alt.Y('rotation_diversity:Q', title='Rotation Diversity'),color=alt.Color('crop_name:N', title='Crop'),size=alt.Size('pct_crop:Q', title='% Crop Coverage'),tooltip=['crop_name', 'year', 'pct_crop', 'rotation_diversity', 'GenLU']).properties(width=800,height=400,title='Crop Coverage vs. Rotation Diversity Over Time')# ---- Layout ----st.altair_chart(area_chart, use_container_width=True)st.altair_chart(scatter, use_container_width=True)# ---- Discussion Section ----st.subheader("🧾 How to Use This Dashboard")
app.py+12-27