Creating a Bar Chart with Altair in Python

  • Share this:

Code introduction


This function creates a bar chart using the Altair library to visualize data. It accepts a DataFrame containing categories and values and generates a bar chart.


Technology Stack : Altair

Code Type : Function

Code Difficulty : Intermediate


                
                    
def bar_chart(data):
    import altair as alt

    # Create a bar chart
    bar_chart = alt.Chart(data).mark_bar().encode(
        x='some_category:O',
        y='some_value:Q'
    )

    return bar_chart                
              
Tags: