Here's an example of how to create a beautiful line chart using Streamlit:

import streamlit as st
import pandas as pd
import altair as alt

# Load data
data = pd.read_csv('data.csv')

# Set chart title
st.title('Sales Data')

# Create line chart
chart = alt.Chart(data).mark_line().encode(
    x='month',
    y='sales',
    color=alt.value('#0072B2')
).properties(
    width=800,
    height=400
)

# Show chart
st.altair_chart(chart, use_container_width=True)

In this example, we are using Altair to create the line chart. We start by loading the data from a CSV file and setting the chart title using st.title().

Next, we create the line chart using Altair's mark_line() function. We encode the 'month' column on the x-axis and the 'sales' column on the y-axis, and set the line color to '#0072B2'. We also set the width and height of the chart using the properties() function.

Finally, we show the chart using st.altair_chart() and set the use_container_width parameter to True to make the chart width responsive to the width of the Streamlit app.

This will result in a beautiful line chart that is interactive and easy to read.


原文地址: https://www.cveoy.top/t/topic/n51C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录