Python – Data Visualisation Code Snippets

Bar Chart

Plot a horizontal bar chart of the data contained in the df Pandas DataFrame.

Count Plot

Pet owners were surveyed to determine their preference for dogs, cats or both. Visualize the response data contained in the list pets.

 

Histogram

Plot a histogram of the pH variable in the wine_quality DataFrame using 40 bins.

 

Plot a histogram of the Ca variable in the glass DataFrame.

Box Plot

Plot boxplots for the sepal_length numerical variable and group according to species.

The data is contained in the iris DataFrame.
The boxplots should be ordered as follows: “virginica”, “versicolor” and “setosa”.

Scatter Plot

Use a + to indicate the points on the scatter plot.

Add a green vertical reference line to the plot at x=50.

Label the x axis as Sepal Length (cm) and the y axis as Sepal Width (cm)

Set the overall font size to be used in plots to 20.

Facet Grid

Initialize a 2×2 grid of facets using the tips dataset. The time variable should determine the number of columns and the smoker variable should determine the number of rows.

Line Plot

Plot the monthly dam level height contained in the dam_level DataFrame.

Plot a line plot of Score as a function of Overall rank. The variables are contained in the happiness DataFrame.

Joint Plot

Plot the regression and kernel density fits for the BPM and Popularity variables in the top50 DataFrame.

 

 

Pair Plot

Create a pair plot of the song_metrics dataset.

 

Kernel Density Estimation / KDE Plot

Plot the distributions of the Mg and Al variables contained in the glass DataFrame on the same plot using kernel density estimation. Shade the distributions.