ridgeplot (python)
Aug 2021 by Francisco Juretig
The ridgeplot library allows us to plot estimated densities for multiple distributions in the same plot. The idea is the following: for example, we may have scores for a test for students in 10 schools, and we want to plot the distributions for those 10 schools. Ideally, we would like to see them all together, since it would be much easier to visualize. There are several options for doing this: we can for example use matplotlib, but it requires some extra code. The ridgeplot library makes it incrdibly easy.
Want this project? You can download it from here (contains the prython project plus the csv input file)
Here we will use prython as our IDE since it allows us to separate our code in a nice way. It is a new R and Python IDE that allows you to put your code in panels that you can connect to each other. Inside each panel you can use any R or python code you would normally use
Note that here we separated the project into three panels. The top one generates the data and loads some libraries. In this case we will use simulated data: in particular, we will have a list of numpy arrays. Each one will contains 600 gaussian random numbers. The objective will be to pass this list to ridgeplot()
In the two panels below, we are calling ridgeplot() with a different bandwidth. On the right, we use the default one. On the left, we use 4. There is no question the default one works better. We can run this very easily by clicking on >> on the first panel. That runs everything connected to out. We could obviously even try more experiments, with different bandwidths. For this, we just need to add more panels and connect them to the OUT part of the first panel.

How do we run it? Each panel has three running modes. You can see the blue carets next to the python button (this button is used to switch between R and python). The first running mode runs only one panel, the second one runs up to that panel (meaning everything that is connected to IN) and the third one runs everything that is connected to OUT (meaning everything that uses the objects defined in here).