Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Heatmap | Matrix Plots
Deep Dive into the seaborn Visualization

book
Heatmap

A heatmap is a plot of rectangular data as a color-encoded matrix. As a parameter, it takes a 2D dataset. That dataset can be coerced into an ndarray.

This is a great way to visualize data because it can show the relation between variables, including time. For instance, the number of flights through the years.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img
Taak

Swipe to start coding

  1. Set the 'ticks' style with the 'seagreen' figure.facecolor.
  2. Create the heatmap using the seaborn library:
  • Add the data for the heatmap. You only need to input the name of the DataFrame (without data = ...);
  • Set the 'viridis' cmap parameter;
  • Add the annot parameter;
  • Set the fmt parameter equals the '0.99g';
  • Set the linecolor parameter equals the 'plum';
  • Display the plot.

Oplossing

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/flights.csv')
# Reshaping the data
upd_df = df.pivot_table(index='month', columns='year', values='passengers')

# Set the 'ticks' style with the 'seagreen' figure facecolor
sns.set_style('ticks', {'figure.facecolor' : 'seagreen'})
# Create a heatmap
sns.heatmap(# Add the data for the heatmap
upd_df,
# Set the cmap
cmap = 'viridis',
# Set the annotation
annot = True,
# Set the fmt
fmt = '0.99g',
# Set the linecolor
linecolor = 'plum')

# Display the plot
plt.show()

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 1
single

single

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/flights.csv')
# Reshaping the data
upd_df = df.pivot_table(index='month', columns='year', values='passengers')

# Set the 'ticks' style with the 'seagreen' figure facecolor
sns.set_style('___', {'___' : ___})
# Create a heatmap
___(# Add the data for the heatmap
___,
# Set the cmap
___ = 'viridis',
# Set the annotation
___ = ___,
# Set the fmt
___ = '0.99g',
# Set the linecolor
___ = '___')

# Display the plot
___

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt