Search code examples
pythonpandasseabornheatmapcorrelation

y-axis of heatmap is wrong


The code I used to create the heatmap is

heat = sns.heatmap(data = df_scaled)
plt.show()

The output of

df_scaled.head().to_dict()

is

{'price': {0: -0.4951825948267441,
  1: -0.5179165100325603,
  2: -0.6129856099841553,
  3: -0.3736594844538357,
  4: 0.10209935921697258},
 'kilometer': {0: 0.5741334672310862,
  1: 0.3622682850489242,
  2: 0.222768576616225,
  3: -0.2916365982293533,
  4: 0.2576435037243998},
 'engine_capacity': {0: -0.7838621075472668,
  1: -0.7046161644027918,
  2: -0.7854470264101563,
  3: -0.7854470264101563,
  4: 1.1101159336056856},
 'length': {0: -0.668002395277177,
  1: -0.6565191920398916,
  2: -1.59814185749729,
  3: -0.6565191920398916,
  4: 1.0429948870783396},
 'width': {0: -0.6610291328230548,
  1: -0.548343442627264,
  2: -1.2995813772658689,
  3: -0.17272447530796162,
  4: 0.4658277691348525},
 'height': {0: -0.6477190383353187,
  1: -0.2743308376964503,
  2: -0.3116696577603371,
  3: -0.610380218271432,
  4: 1.5179325253701186},
 'seating_capacity': {0: -0.3785316600982165,
  1: -0.3785316600982165,
  2: -0.3785316600982165,
  3: -0.3785316600982165,
  4: 2.0933854001176315},
 'fuel_tank_capacity': {0: -1.1577201400333714,
  1: -0.6810738015931533,
  2: -1.1577201400333714,
  3: -1.0215354719075949,
  4: 0.20412654122439455},
 'car_age': {0: -0.1708575773625923,
  1: 0.7212702800919575,
  2: 1.6133981375465072,
  3: -0.7656094823322922,
  4: -0.4682335298474422}}

I thought heatmaps were supposed to plot each column against itself. For example, since I have 9 columns, it would be a 9x9 square. Instead, my y-axis has 2000+ ticks.

Any tips on how to make my x- and y-axis the same?


Solution

  • I think you want to show the correlation between each variables:

    ax = sns.heatmap(data=df_scaled.corr())
    plt.tight_layout()
    plt.show()
    

    enter image description here