How to Make Overlapping Histograms in Python with Altair? Last Updated : 02 Dec, 2020 Comments Improve Suggest changes Like Article Like Report 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. Using Altair, we can make overlapping histograms or layers histograms from data that is in either wide form or long tidy form. Procedure This will common to both forms: Import LibrariesImport or create data.Make the data long/wide according to the method.Plot the histograms. Method 1: Tidy form To make histogram with Altair, we are using mark_area() function. Here we specify transparency level with opacity argument and therefore the key argument that creates histogram is interpolate=’step’. Without that the histogram would appear as area chart from Altair.Then we specify the variables and therefore the number of bins. To differentiate between different plots alt.Color() is employed with the specific variable like multiple histograms. Example : Python3 # importing libraries import pandas as pd import altair as alt import numpy as np np.random.seed(42) # creating data df = pd.DataFrame({'Col A': np.random.normal(-1, 1, 1000), 'Col B': np.random.normal(0, 1, 1000)}) # Overlapping Histograms alt.Chart(pd.melt(df, id_vars=df.index.name, value_vars=df.columns, var_name='Columns', value_name='Values') ).mark_area(opacity=0.5, interpolate='step' ).encode( alt.X('Values', bin=alt.Bin(maxbins=10)), alt.Y('count()', stack=None), alt.Color('Columns') ).add_selection(alt.selection_interval(encodings=['x'])) Output: Method 2: Wide form Often you would possibly start with data that's in wide form. Altair has transform_fold() function which will convert data in wide form to tidy long form. This allows us to not use Pandas’ melt() function and lets us transfer the information within Altair.We specify the variables names that are required to reshape and names for brand spanning new variables within the tidy data. Example : Python3 # importing libraries import pandas as pd import altair as alt import numpy as np np.random.seed(42) # creating data df = pd.DataFrame({'Col 1': np.random.normal(-1, 1, 1000), 'Col 2': np.random.normal(0, 1, 1000)}) # Overlapping Histograms alt.Chart(df).transform_fold( ['Col 1', 'Col 2'], as_=['Columns', 'Values'] ).mark_area( opacity=0.5, interpolate='step' ).encode( alt.X('Values:Q', bin=alt.Bin(maxbins=100)), alt.Y('count()', stack=None), alt.Color('Columns:N') ) Output : Comment More infoAdvertise with us Next Article Python Altair - Scatter Plot D deepanshu_rustagi 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