Creating a 2D histogram
In the first case, we basically counted the observations in each bin of our dataset. In this case, we will do the same but for combinations of bins for both datasets. The bins for each variable will end up creating a matrix. A simple example can make this easy. Let's create one and see:
- Create a subset of
povertycontaining only countries, where the year is equal to2000:df = poverty[poverty['year'].eq(2000) & poverty['is_country']]
- Create a
Figureobject and add ahistogram2dtrace (at the time of writing, this chart type is not available in Plotly Express). We simply select any two indicators that we would like to plot together and pass them toxandy:fig = go.Figure() fig.add_histogram2d(x=df['Income share held by fourth 20%'], Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â y=df['GINI index (World Bank estimate)'], Â ...