Andy Junghyun Kim
Andy Junghyun Kim

Reputation: 69

How to create 2d heatmap from 1d array in python?

As a result of my own function, I get 1d array something like [0.4, 0.6, 0.2, 0.3, 0.9, 0.7]

Now I want to make a heatmap with it, for example,
0.7
0.3 0.9
0.4 0.6 0.2

or

1 0.7 0.3 0.4
0.7 1 0.9 0.6
0.3 0.9 1 0.2
0.4 0.6 0.2 1
with some proper labels.

How do I do this? Please help me.

Thank you in advance.

Upvotes: 0

Views: 391

Answers (1)

NIKUNJ KOTHIYA
NIKUNJ KOTHIYA

Reputation: 2165

You can do this by matplotlib library inside python.

import numpy as np
import matplotlib.pyplot as plt

data = [0.4, 0.6, 0.2, 0.3, 0.9, 0.7]

// reshape your data into 2D array
data = np.array(data).reshape(2, 3)

//  Now plot heatmap for your data show in graph
plt.imshow(data, cmap='hot')
plt.colorbar()
plt.show()

enter image description here

Upvotes: 1

Related Questions