Spaces:
Running
Running
import streamlit as st | |
import altair as alt | |
import pandas as pd | |
# Generate random data for the chart | |
data = pd.DataFrame({ | |
'Category': ['A', 'B', 'C', 'D', 'E'], | |
'Value': [0.2, 0.5, 0.8, 1.2, 1.5] | |
}) | |
# Define the color scale for the bars | |
color_scale = alt.Scale( | |
domain=[0, 1], # Values between 0 and 1 will be blue | |
range=['steelblue', 'lightgray'] | |
) | |
# Create the bar chart using Altair | |
chart = alt.Chart(data).mark_bar().encode( | |
x='Category', | |
y='Value', | |
color=alt.Color('Value', scale=color_scale) | |
) | |
# Render the chart using Streamlit | |
st.altair_chart(chart, use_container_width=True) |