热图的纵轴错误。

huangapple go评论69阅读模式
英文:

y-axis of heatmap is wrong

问题

以下是要翻译的内容:

我用于创建热图的代码是

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

输出

df_scaled.head().to_dict()

{'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}}

我以为热图应该绘制每一列与自身的关系。例如,我有9列,应该是一个9x9的正方形。但实际上,我的y轴上有2000多个刻度。

有关如何使我的x轴和y轴相同的提示吗?

英文:

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?

答案1

得分: 1

我认为您想要展示每个变量之间的相关性:

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

热图的纵轴错误。

英文:

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

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

热图的纵轴错误。

答案2

得分: 0

如果您想修复Y轴刻度,您可以使用以下代码:

import matplotlib.pyplot as plt
import numpy as np

plt.yticks(np.arange(min, max, step))
英文:

If you would like to fix Y-axis ticks you can use this:

import matplotlib.pyplot as plt
import numpy as np

plt.yticks(np.arange(min, max, step))

huangapple
  • 本文由 发表于 2023年6月5日 16:40:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定