VOOZH about

URL: https://www.geeksforgeeks.org/python/plotting-correlation-matrix-using-python/

⇱ Plotting Correlation Matrix using Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Plotting Correlation Matrix using Python

Last Updated : 23 Jul, 2025

Correlation means an association, It is a measure of the extent to which two variables are related. 

1. Positive Correlation: When two variables increase together and decrease together. They are positively correlated. '1' is a perfect positive correlation. For example - demand and profit are positively correlated the more the demand for the product, the more profit hence positive correlation.

πŸ‘ Image

2. Negative Correlation: When one variable increases and the other variable decreases together and vice-versa. They are negatively correlated. For example, If the distance between magnet increases their attraction decreases, and vice-versa. Hence, a negative correlation. '-1'  is no correlation

πŸ‘ Image

3. Zero Correlation( No Correlation): When two variables don't seem to be linked at all. '0' is a perfect negative correlation. For Example, the amount of tea you take and level of intelligence.

πŸ‘ Image

Plotting Correlation matrix using Python

Step 1: Importing the libraries.

Step 2: Finding the Correlation between two variables.

Output:

πŸ‘ Image

Step 3: Plotting the graph. Here we are using scatter plots. A scatter plot is a diagram where each value in the data set is represented by a dot. Also, it shows a relationship between two variables.

Output:

πŸ‘ Image

Remember the points that were explained above. Observe both the images you will find similarity Also, observe the value of the correlation is near to 1, hence the positive correlation is reflected.

Adding title and labels in the graph

Output:

πŸ‘ Image

Plot using Heatmaps

There are many ways you can plot correlation matrices one efficient way is using the heatmap. It is very easy to understand the correlation using heatmaps it tells the correlation of one feature(variable) to every other feature(variable). In other words, A correlation matrix is a tabular data representing the β€˜correlations’ between pairs of variables in a given data.

Output:

πŸ‘ Image

Comment
Article Tags: