Create Grouped Bar Chart using Altair in Python Last Updated : 16 Mar, 2021 Comments Improve Suggest changes Like Article Like Report Grouped bar charts are a handy tool to represent our data when we want to compare multiple sets of data items one against another. To make a grouped bar chart, we require at least three rows of three columns of data in our dataset. The three columns can be used as- one for values, one for series, and one for categories. In a grouped bar chart, the data values present in a series are represented side by side and are grouped under specific categories so that their values can be represented accordingly over the axis. All the data values belonging to a specific series will always be represented with the same color across all the categories. Let's take an example, suppose, we want to compare the runs made by two players across three formats. Here, runs scored by the players act as values, Player name acts as a series and the format of the game acts as the categories. Always, the runs scored by each player will have the same color representation across the different formats. In this article, we will learn to create a grouped bar chart using Altair library in Python. As we discussed, we need at least three rows/columns, we will begin with importing necessary libraries and then creating a dataset having three columns using pandas library. Example 1: Python import altair as alt import pandas as pd # creating a custom dataframe data = pd.DataFrame([[264, 'Rohit', 'ODI'], [183, 'Virat', 'ODI'], [118, 'Rohit', 'T20'], [94, 'Virat', 'T20'], [212, 'Rohit','Test'], [254, 'Virat','Test']], columns=['Highest Score', 'Player', 'Format']) print(data) Output: Now, that we have a dataset containing three columns, where we want to compare the highest score (values) of two players (series) across different formats (categories). Python gp_chart = alt.Chart(data).mark_bar().encode( alt.Column('Format'), alt.X('Player'), alt.Y('Highest Score', axis=alt.Axis(grid=False)), alt.Color('Player')) gp_chart.display() Output: We can plot a group chart by calling the alt.Chart() method present inside Altair library. We want our categories to be displayed as the columns so, we can pass Format inside the alt.Column() method, our series (players) will be represented on the x-axis hence we pass Player in the alt.X() field, and our values (runs) should be displayed on y-axis so we pass Highest Score inside the alt.Y() field. Each player should have same color in all formats so, we pass Player inside the alt.Color() method. Example 2: Python3 # importing package import altair as alt import pandas as pd # create data data = pd.DataFrame([['A', 10, 20], ['B', 5, 29], ['A', 15, 29], ['B', 15, 20]], columns=['Team', 'Round 1', 'Round 2']) # view data print(data) gp_chart = alt.Chart(data).mark_bar().encode( alt.Column('Round 2'), alt.X('Team'), alt.Y('Round 1', axis=alt.Axis(grid=False)), alt.Color('Team')) gp_chart.display() Output: Comment More infoAdvertise with us Next Article Scatter Plot with Regression Line using Altair in Python saurabh48782 Follow Improve Article Tags : Python Python-Altair Practice Tags : python Similar Reads Introduction to Altair in Python Altair is a statistical visualization library in Python. It is a declarative in nature and is based on Vega and Vega-Lite visualization grammars. It is fast becoming the first choice of people looking for a quick and efficient way to visualize datasets. If you have used imperative visualization libr 5 min read Create Grouped Bar Chart using Altair in Python Grouped bar charts are a handy tool to represent our data when we want to compare multiple sets of data items one against another. To make a grouped bar chart, we require at least three rows of three columns of data in our dataset. The three columns can be used as- one for values, one for series, an 3 min read Scatter Plot with Regression Line using Altair in Python Prerequisite: Altair In this article, we are going to discuss how to plot to scatter plots with a regression line using the Altair library. Scatter Plot and Regression Line The values of two different numeric variables is represented by dots or circle in Scatter Plot. Scatter Plot is also known as a 4 min read Horizontal Stripplot with Jitter using Altair in Python Prerequisites: Altair Altair is a statistical data visualization library in python which is based on Vega and Vega-Lite visualization grammars. A Stripplot is used for graphical data analysis. Â It is a simple plot of response values in a sorted order along a single axis. The strip plot consists of 2 2 min read How To Make Stripplot with Jitter in Altair Python? Prerequisites: Altair Altair is a statistical data visualization library in python which is based on Vega and Vega-Lite visualization grammars. A Stripplot is used for graphical data analysis. Â It is a simple plot of response values in a sorted order along a single axis. The strip plot consists of 2 3 min read How To Facet a Scatter Plot with Altair? In this article, we will learn how to Facet a Scatter Plot with Altair. Let's recall some concepts : Altair is a statistical visualization library in Python. It is declarative in nature and is based on Vega and Vega-Lite visualization grammars. It is fast becoming the first choice of people looking 3 min read How to Make a Simple Histogram with Altair in Python? Prerequisites: Altair Simple Histogram is the representation of frequency distribution by means of rectangles whose width represents the class interval. Histogram is the graphical representation that organizes grouped data points into the specified range. By using histogram we can visualize large am 4 min read Area Chart with Altair in Python Prerequisite: Introduction to Altair in Python An Area Graph shows the change in a quantitative quantity with respect to some other variable. It is simply a line chart where the area under the curve is colored/shaded. It is best used to visualize trends over a period of time, where you want to see h 2 min read How to Make Overlapping Histograms in Python with Altair? Prerequisite: Altair A histogram represents data provided during a sort of some groups. It is an accurate method for the graphical representation of numerical data distribution. It is a kind of bar plot where the X-axis represents the bin ranges while the Y-axis gives information about frequency. Us 2 min read Python Altair - Scatter Plot In this article, we will learn a Simple Scatter plot with Altair using python. Altair is one of the latest interactive data visualizations library in python. Altair is based on vega and vegalite- A grammar of interactive graphics. Â Here we will import the Altair library for using it. And then we wil 2 min read Like