2

I use seaborn modules to plot the heatmap of one of the Wifi AP within a specific area. The heatmap plot was according to my specifications. However, I would like to change the X-and Y-axis Label from a letter to a number. For example, A letter should be 0.45, B should be 0.90, and the last letter O should be 6.75 number.

I have axis labels ABCDEFGHIJKLMNO and would like to change them to the labels 0.45 0.90 1.35 1.80 2.25 2.70 3.15 3.60 4.05 4.50 4.95 5.40 5.85 6.30 6.75.

Moreover, I would like to add x-label as x(m) and y-label as y(m), the label on the x and y-axis in the graph. I have already tried this in the example below, but these labels are not being displayed.

import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
array = [[-45,-45,-46,-47,-48,-49,-48,-50,-52,-51,-53,-54,-56,-58,-57], 
        [-44,-45,-47,-48,-49,-48,-48,-51,-50,-52,-54,-54,-56,-58,-57], 
        [-45,-46,-48,-47,-50,-50,-49,-50,-52,-51,-53,-54,-56,-58,-56], 
        [-46,-48,-47,-47,-51,-50,-48,-50,-49,-50,-52,-53,-54,-54,-55], 
        [-47,-50,-49,-47,-49,-49,-48,-50,-52,-51,-53,-54,-56,-56,-55], 
        [-48,-51,-49,-49,-50,-51,-50,-52,-53,-51,-52,-52,-52,-57,-56], 
        [-47,-52,-47,-50,-48,-49,-48,-50,-52,-51,-53,-52,-50,-54,-53],
        [-47,-49,-48,-49,-47,-48,-47,-49,-50,-50,-51,-52,-54,-55,-54], 
        [-49,-48,-47,-48,-47,-49,-48,-50,-51,-51,-53,-52,-53,-55,-53], 
        [-50,-48,-48,-47,-49,-50,-48,-49,-52,-52,-53,-54,-51,-58,-55], 
        [-52,-49,-49,-51,-48,-51,-48,-50,-53,-53,-53,-51,-52,-57,-54], 
        [-53,-51,-49,-51,-50,-51,-49,-52,-53,-54,-53,-53,-52,-56,-55], 
        [-51,-50,-51,-50,-51,-52,-50,-53,-54,-52,-53,-53,-54,-54,-53], 
        [-52,-52,-52,-53,-52,-54,-53,-56,-55,-53,-52,-54,-53,-55,-53], 
        [-54,-53,-53,-52,-54,-55,-56,-56,-54,-53,-53,-54,-56,-58,-54]]
df_cm = pd.DataFrame(array, index = [i for i in "ABCDEFGHIJKLMNO"],
                  columns = [i for i in "ABCDEFGHIJKLMNO"])
plt.figure(figsize = (10,7))
plt.title('AP1')
plt.xlabel('x(m)')
plt.ylabel('y(m)')
sn.heatmap(df_cm, annot=False)
plt.savefig('heatmap.png')
plt.savefig('heatmap.pdf')

Heatmap example

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Reyha
  • 127
  • 1
  • 2
  • 9

1 Answers1

8

Is this what you are aiming for? Note how I moved the xlabel and ylabel generation after the sn.heatmap call.

import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
array = [[-45,-45,-46,-47,-48,-49,-48,-50,-52,-51,-53,-54,-56,-58,-57], 
        [-44,-45,-47,-48,-49,-48,-48,-51,-50,-52,-54,-54,-56,-58,-57], 
        [-45,-46,-48,-47,-50,-50,-49,-50,-52,-51,-53,-54,-56,-58,-56], 
        [-46,-48,-47,-47,-51,-50,-48,-50,-49,-50,-52,-53,-54,-54,-55], 
        [-47,-50,-49,-47,-49,-49,-48,-50,-52,-51,-53,-54,-56,-56,-55], 
        [-48,-51,-49,-49,-50,-51,-50,-52,-53,-51,-52,-52,-52,-57,-56], 
        [-47,-52,-47,-50,-48,-49,-48,-50,-52,-51,-53,-52,-50,-54,-53],
        [-47,-49,-48,-49,-47,-48,-47,-49,-50,-50,-51,-52,-54,-55,-54], 
        [-49,-48,-47,-48,-47,-49,-48,-50,-51,-51,-53,-52,-53,-55,-53], 
        [-50,-48,-48,-47,-49,-50,-48,-49,-52,-52,-53,-54,-51,-58,-55], 
        [-52,-49,-49,-51,-48,-51,-48,-50,-53,-53,-53,-51,-52,-57,-54], 
        [-53,-51,-49,-51,-50,-51,-49,-52,-53,-54,-53,-53,-52,-56,-55], 
        [-51,-50,-51,-50,-51,-52,-50,-53,-54,-52,-53,-53,-54,-54,-53], 
        [-52,-52,-52,-53,-52,-54,-53,-56,-55,-53,-52,-54,-53,-55,-53], 
        [-54,-53,-53,-52,-54,-55,-56,-56,-54,-53,-53,-54,-56,-58,-54]]

labels = [0.45, 0.90, 1.35, 1.80, 2.25, 2.70, 3.15, 3.60, 4.05, 4.50, 4.95, 5.40, 5.85, 6.30, 6.75]
df_cm = pd.DataFrame(array, index = labels,
                  columns = labels)
plt.figure(figsize = (10,7))
plt.title('AP1')
sn.heatmap(df_cm, annot=False)
plt.xlabel('x(m)')
plt.ylabel('y(m)')
plt.savefig('heatmap.png')
plt.savefig('heatmap.pdf')

enter image description here

André
  • 1,034
  • 9
  • 19