0% found this document useful (0 votes)
62 views5 pages

Heatmap 2D - Jupyter Notebook

The document contains code to generate heatmaps from 6 different datasets using matplotlib in Python. For each dataset, the code defines the data, creates a heatmap plot using pcolor, customizes the plot layout and labels, adds a title and colorbar, and displays the figure. The heatmaps visualize temperature, humidity, wind speed, light intensity, and sound intensity data over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views5 pages

Heatmap 2D - Jupyter Notebook

The document contains code to generate heatmaps from 6 different datasets using matplotlib in Python. For each dataset, the code defines the data, creates a heatmap plot using pcolor, customizes the plot layout and labels, adds a title and colorbar, and displays the figure. The heatmaps visualize temperature, humidity, wind speed, light intensity, and sound intensity data over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

In [1]: import numpy as np

import matplotlib.pyplot as plt



# Define data
data = np.array([[27.1, 27.1, 27, 27, 27.1, 27.2],
[27, 27.1, 27, 27, 27.11, 27.2],
[27.1, 27.1, 27, 26.9, 27.1, 27.3],
[27.1, 27.1, 27, 26.8, 27, 27.3],
[27, 27.1, 27, 26.7, 26.7, 27.5],
[27.1, 27.1, 27, 26.6, 26.6, 27.4]])

# Create heatmap
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap='Reds')

# Set ticks
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)

# Set tick labels
ax.set_xticklabels(np.arange(1, data.shape[1] + 1), minor=False)
ax.set_yticklabels(np.arange(1, data.shape[0] + 1), minor=False)

# Rotate tick labels and set font size
plt.xticks(rotation=45)
plt.tick_params(axis='both', which='major', labelsize=10)

# Set title and colorbar
plt.title("Temperatur")
cbar = plt.colorbar(heatmap)

# Show plot
plt.show()

In [3]: import numpy as np
import matplotlib.pyplot as plt

# Define data
data = np.array([[76.1, 76.1, 76.3, 76.3, 76.1, 76.1],
[76.2, 76.2, 76.2, 76.3, 76.1, 76.1],
[76.1, 76.2, 76.2, 76.3, 76.2, 76.1],
[76.2, 76.2, 76.2, 76.3, 76.2, 76.1],
[76, 76.2, 76.2, 76.2, 76, 76.1],
[76.1, 76.2, 76.2, 76.2, 76.1, 76.1]])

# Create heatmap
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap='Blues')

# Set ticks
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)

# Set tick labels
ax.set_xticklabels(np.arange(1, data.shape[1] + 1), minor=False)
ax.set_yticklabels(np.arange(1, data.shape[0] + 1), minor=False)

# Rotate tick labels and set font size
plt.xticks(rotation=45)
plt.tick_params(axis='both', which='major', labelsize=10)

# Set title and colorbar
plt.title("Kelembapan Udara")
cbar = plt.colorbar(heatmap)

# Show plot
plt.show()

In [4]: import numpy as np
import matplotlib.pyplot as plt

# Define data
data = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0.8, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]])

# Create heatmap
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap='Greys')

# Set ticks
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)

# Set tick labels
ax.set_xticklabels(np.arange(1, data.shape[1] + 1), minor=False)
ax.set_yticklabels(np.arange(1, data.shape[0] + 1), minor=False)

# Rotate tick labels and set font size
plt.xticks(rotation=45)
plt.tick_params(axis='both', which='major', labelsize=10)

# Set title and colorbar
plt.title("Kecepatan Angin")
cbar = plt.colorbar(heatmap)

# Show plot
plt.show()

In [5]: import numpy as np
import matplotlib.pyplot as plt

# Define data
data = np.array([[117, 98, 148, 151, 185, 190],
[76, 149, 179, 203, 190, 177],
[146, 117, 178, 188, 162, 174],
[50, 105, 147, 175, 177, 185],
[60, 83, 137, 141, 208, 171],
[4.4, 81, 150, 154, 164, 230]])

# Create heatmap
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap='afmhot')

# Set ticks
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)

# Set tick labels
ax.set_xticklabels(np.arange(1, data.shape[1] + 1), minor=False)
ax.set_yticklabels(np.arange(1, data.shape[0] + 1), minor=False)

# Rotate tick labels and set font size
plt.xticks(rotation=45)
plt.tick_params(axis='both', which='major', labelsize=10)

# Set title and colorbar
plt.title("Kuat Pencahayaan")
cbar = plt.colorbar(heatmap)

# Show plot
plt.show()

In [6]: import numpy as np
import matplotlib.pyplot as plt

# Define data
data = np.array([[60, 63.8, 69.1, 71.9, 52.6, 66.4],
[62.6, 47.4, 66.6, 63, 60.3, 63],
[58.2, 58, 61.8, 62.4, 60, 68],
[64.9, 62.1, 65.1, 59.9, 60.2, 60.7],
[63.6, 57.2, 63.8, 60.6, 58.6, 67.1],
[63.1, 64.1, 61.5, 66.7, 60.6, 54.3]])

# Create heatmap
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap='cool')

# Set ticks
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)

# Set tick labels
ax.set_xticklabels(np.arange(1, data.shape[1] + 1), minor=False)
ax.set_yticklabels(np.arange(1, data.shape[0] + 1), minor=False)

# Rotate tick labels and set font size
plt.xticks(rotation=45)
plt.tick_params(axis='both', which='major', labelsize=10)

# Set title and colorbar
plt.title("Intensitas Suara")
cbar = plt.colorbar(heatmap)

# Show plot
plt.show()

You might also like