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.









Taak
Swipe to start coding
- Set the
'ticks'
style with the'seagreen'
figure.facecolor
. - Create the
heatmap
using theseaborn
library:
- Add the data for the
heatmap
. You only need to input the name of the DataFrame (withoutdata = ...
); - 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
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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?
Bedankt voor je feedback!
Sectie 4. Hoofdstuk 1
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.