Get startedGet started for free

Bivariate visualizations

1. Bivariate visualizations

Let's learn about visualizing more than one variable in plots.

2. What are bivariate visualizations?

Bivariate plots display and compare two variables or two attributes of a dataset. Some common examples include: scatterplots, line charts, and correlation plots.

3. scatterplot

A scatterplot is a graph that includes A y axis for one variable. An x axis for a different variable. Each intersection is a dot on the graph. Here's an example: a dot is positioned at 68 on the x-axis and 472 on the y-axis.

4. scatterplot with plotly.express

Let's create a scatterplot with plotly express to visualize the body mass and flipper length of our penguins. We import the library. Just like bar and histograms, we specify the DataFrame, and the main arguments are column names as strings. Nice. The hover also provides the x and y values automatically.

5. More plotly.express arguments

Here are more useful arguments for a Plotly express scatterplot. You can add different types of trend lines. You can also set different symbols for different categorical values, such as stars or triangles, instead of the default circles. As always, check the documentation for more.

6. Line charts in plotly.express

A line chart is a common way to show how a variable changes over time. We'll create a line chart of Microsoft's monthly stock price over the past five years using Plotly Express. The code is familiar, specifying the DataFrame and relevant columns. The "Open" column represents the opening stock price. This time, we have also added a title. This is what we produce.

7. Correlation plot

A correlation plot visualizes the correlation between several variables. The Pearson Correlation Coefficient summarizes the strength and direction of the relationship. It ranges from -1 to 1: 1 means perfectly positively correlated, 0 means no correlation, -1 means perfectly negatively correlated.

8. Correlation plot setup

For this example, we'll look at bike rental data alongside weather conditions. We calculate the correlation matrix using the built-in dot corr method from pandas. The resulting table shows Pearson values at each variable intersection. The diagonal values are all 1 since a variable is perfectly correlated with itself.

9. Correlation plot with Plotly

To visualize this, we can use Plotly Express with imshow. The imshow function is designed to display matrices like our correlation matrix as heatmaps. We pass our correlation matrix to the function as the first argument. We set text auto to True to show the correlation values in each cell for better readability. We set the color scale to this value for red, yellow, and green and fixed the min-max values to -1 and 1, ensuring proper color representation of correlation strength. Finally, we display with fig.show().

10. Our correlation plot

And here's our correlation plot. Each intersection shows a Pearson coefficient. We can see that bike rentals positively correlate with temperature and visibility, and negatively correlate with snow, rain, and humidity.

11. Let's practice!

Let's create some bivariate visualizations to explore our data!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.