Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
DCELL
Contributor

seaborn plot not rendering properly

I'm running this code which you can find in the microsoft learn docs. Only the first row of the matrix has numbers, when they all should have numbers

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

# Load the penguins dataset
penguins = pd.read_csv('https://raw.githubusercontent.com/MicrosoftLearning/dp-data/main/penguins.csv')

# Calculate the correlation matrix
corr = penguins.corr()

# Create a heatmap
sns.heatmap(corr, annot=True)
plt.show()

 

Result:

DCELL_0-1742856766905.png

 

Expected result:

Apply advanced data exploration techniques - Training | Microsoft Learn

 

1 ACCEPTED SOLUTION
v-veshwara-msft
Honored Contributor II

Hi @DCELL ,
Thanks for posting in Microsoft Fabric Community,

The issue where only the first row of numbers is showing up in the heatmap happens because Seaborn sometimes hides text when it automatically places the annotations. This can make some values disappear, especially when the background color is too dark or light.

 

To fix this, manually add the numbers using plt.text(). This makes sure that all values are placed clearly inside each cell, so nothing gets hidden or overwritten. It also gives better control over how the numbers look, making them easy to read no matter the background color.

 

Here is the updated code and output:

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Load the dataset
penguins = pd.read_csv('https://raw.githubusercontent.com/MicrosoftLearning/dp-data/main/penguins.csv')

# Calculate the correlation matrix
corr = penguins.corr()

# Create heatmap without annotations
ax = sns.heatmap(
    corr, 
    cmap='coolwarm', 
    linewidths=0.5, 
    vmin=-1, vmax=1, 
    cbar_kws={"shrink": 0.8}
)

# Manually add text annotations for every cell
for i in range(corr.shape[0]):
    for j in range(corr.shape[1]):
        plt.text(
            j + 0.5,  # X position
            i + 0.5,  # Y position
            f"{corr.iloc[i, j]:.2f}",  # Text content
            ha='center', 
            va='center', 
            color='black', 
            fontsize=10, 
        )

plt.show()

vveshwaramsft_0-1742887182884.png

Hope this helps. Please reach out forfurther assistance.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and a kudos would be appreciated.

 

Regards,
Vinay.

 

View solution in original post

1 REPLY 1
v-veshwara-msft
Honored Contributor II

Hi @DCELL ,
Thanks for posting in Microsoft Fabric Community,

The issue where only the first row of numbers is showing up in the heatmap happens because Seaborn sometimes hides text when it automatically places the annotations. This can make some values disappear, especially when the background color is too dark or light.

 

To fix this, manually add the numbers using plt.text(). This makes sure that all values are placed clearly inside each cell, so nothing gets hidden or overwritten. It also gives better control over how the numbers look, making them easy to read no matter the background color.

 

Here is the updated code and output:

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Load the dataset
penguins = pd.read_csv('https://raw.githubusercontent.com/MicrosoftLearning/dp-data/main/penguins.csv')

# Calculate the correlation matrix
corr = penguins.corr()

# Create heatmap without annotations
ax = sns.heatmap(
    corr, 
    cmap='coolwarm', 
    linewidths=0.5, 
    vmin=-1, vmax=1, 
    cbar_kws={"shrink": 0.8}
)

# Manually add text annotations for every cell
for i in range(corr.shape[0]):
    for j in range(corr.shape[1]):
        plt.text(
            j + 0.5,  # X position
            i + 0.5,  # Y position
            f"{corr.iloc[i, j]:.2f}",  # Text content
            ha='center', 
            va='center', 
            color='black', 
            fontsize=10, 
        )

plt.show()

vveshwaramsft_0-1742887182884.png

Hope this helps. Please reach out forfurther assistance.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and a kudos would be appreciated.

 

Regards,
Vinay.

 

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (14,788)