How to change the labels of an area chart on Streamlit?

Question:

I have deployed an area chart using Streamlit for Python. Is it possible to change the labels for the axis X, as well as the labels for each data point plotted?

import streamlit as st
import pandas as pd
st.write(""" My area chart """)
df = pd.read_csv("my_data.csv")
st.area_chart(df)
Asked By: Julio S.

||

Answers:

Let`s look on this example:

import numpy as np
chart_data = pd.DataFrame([[1, 2, 1], [0, 2, 1], [1, 3, 5]],
                          columns=['a', 'b', 'c'],
                          index=[1, 2, 3])
st.area_chart(chart_data)

enter image description here

For changing the x axis labels you can just change the index (it can be int/float or datetime for example). For changing the groups names you can change the columns names in your dataframe.

Answered By: theletz

You can try something like this:

import streamlit as st
import pandas as pd
st.write(""" My area chart """)
df = pd.read_csv("my_data.csv")
fig=px.area_chart(df)
fig.update_layout(
        xaxis_title="Description of x axis", yaxis_title="Description of y axis"
    )
st.plotly_chart(fig)
Answered By: Maria