绘制热图图未渲染所有yAxis标签
问题描述
我构建了一个带有热图的仪表板。然而,我注意到t=y轴上的一些标签没有显示。我只是拿到了限制版,我不确定出了什么问题。这是我的仪表板:
import dash
import dash_table
import plotly.graph_objs as go
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input,Output
import pandas as pd
import os
import numpy as np
#correlation dataframe
correlation_df = supervisor[['Características (D)', 'Características (I)',
'Características (S)', 'Características (C)', 'Motivación (D)',
'Motivación (I)', 'Motivación (S)', 'Motivación (C)', 'Bajo Stress (D)',
'Bajo Stress (I)', 'Bajo Stress (S)', 'Bajo Stress (C)','span','Mean Team Performance','employment span','Pay to team size ratio']]
correlation_df = correlation_df.corr()
corr_fig = go.Figure()
corr_fig.add_trace(go.Heatmap(
z= correlation_df.values,
x= ['Características (D)', 'Características (I)',
'Características (S)', 'Características (C)', 'Motivación (D)',
'Motivación (I)', 'Motivación (S)', 'Motivación (C)', 'Bajo Stress (D)',
'Bajo Stress (I)', 'Bajo Stress (S)', 'Bajo Stress (C)','span','Mean Team Performance','employment span','Pay to team size ratio'],
y= ['Características (D)', 'Características (I)',
'Características (S)', 'Características (C)', 'Motivación (D)',
'Motivación (I)', 'Motivación (S)', 'Motivación (C)', 'Bajo Stress (D)',
'Bajo Stress (I)', 'Bajo Stress (S)', 'Bajo Stress (C)','span','Mean Team Performance','employment span','Pay to team size ratio'],
hoverongaps=False
))
corr_fig.update_layout(title="Correlation heatmap",
yaxis={"title": 'Traits'},
xaxis={"title": 'Traits',"tickangle": 45}, )
app = dash.Dash()
#html layout
app.layout = html.Div(children=[
html.H1(children='Dashboard', style={
'textAlign': 'center',
'height': '10'
}),
dcc.Graph(
id='heatmap',
figure=corr_fig.to_dict()
)
])
if __name__ == '__main__':
app.run_server(debug=True)
以下是我的数据框示例:
{'Características (D)': {'Características (D)': 1.0,
'Características (I)': -0.744432853713455,
'Características (S)': 0.20085563028990697,
'Características (C)': -0.039907357919985106,
'Motivación (D)': 0.8232188768568326,
'Motivación (I)': -0.6987940156295481,
'Motivación (S)': 0.17336394623619988,
'Motivación (C)': -0.03941838984936696,
'Bajo Stress (D)': 0.8142337605566142,
'Bajo Stress (I)': -0.48861318810993065,
'Bajo Stress (S)': 0.3207614659369065,
'Bajo Stress (C)': -0.0461134826855843,
'span': 0.2874881163983965,
'Mean Team Performance': 0.40633858242603244,
'employment span': -0.09857697245687172,
'Pay to team size ratio': 0.022958588188126107},
'Características (I)': {'Características (D)': -0.744432853713455,
'Características (I)': 1.0,
'Características (S)': -0.3779100652350093,
'Características (C)': -0.11879176229148546,
'Motivación (D)': -0.8454566900924195,
'Motivación (I)': 0.8314885901746485,
'Motivación (S)': -0.5493813305976118,
'Motivación (C)': 0.020902885445784,
'Bajo Stress (D)': -0.4614762821424876,
'Bajo Stress (I)': 0.8628000011272827,
'Bajo Stress (S)': 0.07723803992022794,
'Bajo Stress (C)': -0.26492408476089707,
'span': -0.2923189384010105,
'Mean Team Performance': -0.04150083345671622,
'employment span': 0.4006484556146567,
'Pay to team size ratio': 0.27081339758378836},
'Características (S)': {'Características (D)': 0.20085563028990697,
'Características (I)': -0.3779100652350093,
'Características (S)': 1.0,
'Características (C)': -0.7739057580439489,
'Motivación (D)': 0.28928161764191546,
'Motivación (I)': -0.14811042351159115,
'Motivación (S)': 0.7823864767779756,
'Motivación (C)': -0.6651182815949327,
'Bajo Stress (D)': 0.10162624205618695,
'Bajo Stress (I)': -0.5488737066087104,
'Bajo Stress (S)': 0.46905181352171205,
'Bajo Stress (C)': -0.4698328671560004,
'span': -0.02087671997992093,
'Mean Team Performance': -0.12496266913575294,
'employment span': 0.27001694775950746,
'Pay to team size ratio': 0.07931062556531454},
'Características (C)': {'Características (D)': -0.039907357919985106,
'Características (I)': -0.11879176229148546,
'Características (S)': -0.7739057580439489,
'Características (C)': 1.0,
'Motivación (D)': -0.011616389427962759,
'Motivación (I)': -0.292733356844308,
'Motivación (S)': -0.4343733032773228,
'Motivación (C)': 0.774357808826908,
'Bajo Stress (D)': -0.04367706074639601,
'Bajo Stress (I)': 0.0931714388059811,
'Bajo Stress (S)': -0.6482541912883304,
'Bajo Stress (C)': 0.7732581689662739,
'span': 0.03775247426826095,
'Mean Team Performance': -0.07825282894287325,
'employment span': -0.5003613024138532,
'Pay to team size ratio': -0.20937248430293648},
'Motivación (D)': {'Características (D)': 0.8232188768568326,
'Características (I)': -0.8454566900924195,
'Características (S)': 0.28928161764191546,
'Características (C)': -0.011616389427962759,
'Motivación (D)': 1.0,
'Motivación (I)': -0.6401977926528387,
'Motivación (S)': 0.27806883694592277,
'Motivación (C)': -0.2534345146499511,
'Bajo Stress (D)': 0.35748019323906,
'Bajo Stress (I)': -0.7219032007713697,
'Bajo Stress (S)': 0.21293087519106632,
'Bajo Stress (C)': 0.2698254124168881,
'span': 0.5037240436882805,
'Mean Team Performance': 0.48414442720369955,
'employment span': -0.20711331594020507,
'Pay to team size ratio': -0.3769998767635495},
'Motivación (I)': {'Características (D)': -0.6987940156295481,
'Características (I)': 0.8314885901746485,
'Características (S)': -0.14811042351159115,
'Características (C)': -0.292733356844308,
'Motivación (D)': -0.6401977926528387,
'Motivación (I)': 1.0,
'Motivación (S)': -0.48288361435623983,
'Motivación (C)': -0.4135335004412625,
'Bajo Stress (D)': -0.5563645790627242,
'Bajo Stress (I)': 0.45272622386580263,
'Bajo Stress (S)': 0.31345796324782077,
'Bajo Stress (C)': -0.1236088717264958,
'span': -0.4334332491868192,
'Mean Team Performance': -0.027223644357210867,
'employment span': 0.08277408562811393,
'Pay to team size ratio': 0.30770777808996924},
'Motivación (S)': {'Características (D)': 0.17336394623619988,
'Características (I)': -0.5493813305976118,
'Características (S)': 0.7823864767779756,
'Características (C)': -0.4343733032773228,
'Motivación (D)': 0.27806883694592277,
'Motivación (I)': -0.48288361435623983,
'Motivación (S)': 1.0,
'Motivación (C)': -0.23220036735524985,
'Bajo Stress (D)': 0.12079023858043715,
'Bajo Stress (I)': -0.5418626995091027,
'Bajo Stress (S)': -0.12381340765657087,
'Bajo Stress (C)': -0.3091698232697242,
'span': 0.1503231802207429,
'Mean Team Performance': -0.38838798587565976,
'employment span': 0.09981399691805137,
'Pay to team size ratio': -0.20858825983296703},
'Motivación (C)': {'Características (D)': -0.03941838984936696,
'Características (I)': 0.020902885445784,
'Características (S)': -0.6651182815949327,
'Características (C)': 0.774357808826908,
'Motivación (D)': -0.2534345146499511,
'Motivación (I)': -0.4135335004412625,
'Motivación (S)': -0.23220036735524985,
'Motivación (C)': 1.0,
'Bajo Stress (D)': 0.18028688548066718,
'Bajo Stress (I)': 0.386437402512207,
'Bajo Stress (S)': -0.7351725371592022,
'Bajo Stress (C)': 0.21452556505271267,
'span': 0.15796613914842977,
'Mean Team Performance': -0.11411844367303944,
'employment span': -0.1335403092401566,
'Pay to team size ratio': -0.16110863218572585},
'Bajo Stress (D)': {'Características (D)': 0.8142337605566142,
'Características (I)': -0.4614762821424876,
'Características (S)': 0.10162624205618695,
'Características (C)': -0.04367706074639601,
'Motivación (D)': 0.35748019323906,
'Motivación (I)': -0.5563645790627242,
'Motivación (S)': 0.12079023858043715,
'Motivación (C)': 0.18028688548066718,
'Bajo Stress (D)': 1.0,
'Bajo Stress (I)': -0.1849352428080063,
'Bajo Stress (S)': 0.2529157606770202,
'Bajo Stress (C)': -0.31055770095686547,
'span': -0.11631187918782246,
'Mean Team Performance': 0.05369401779765192,
'employment span': -0.042901905999867325,
'Pay to team size ratio': 0.4484652828139771},
'Bajo Stress (I)': {'Características (D)': -0.48861318810993065,
'Características (I)': 0.8628000011272827,
'Características (S)': -0.5488737066087104,
'Características (C)': 0.0931714388059811,
'Motivación (D)': -0.7219032007713697,
'Motivación (I)': 0.45272622386580263,
'Motivación (S)': -0.5418626995091027,
'Motivación (C)': 0.386437402512207,
'Bajo Stress (D)': -0.1849352428080063,
'Bajo Stress (I)': 1.0,
'Bajo Stress (S)': -0.0981237735359993,
'Bajo Stress (C)': -0.27961420029017486,
'span': -0.06711566955045667,
'Mean Team Performance': 0.06327392392569486,
'employment span': 0.5471491483201977,
'Pay to team size ratio': 0.17612214868518486},
'Bajo Stress (S)': {'Características (D)': 0.3207614659369065,
'Características (I)': 0.07723803992022794,
'Características (S)': 0.46905181352171205,
'Características (C)': -0.6482541912883304,
'Motivación (D)': 0.21293087519106632,
'Motivación (I)': 0.31345796324782077,
'Motivación (S)': -0.12381340765657087,
'Motivación (C)': -0.7351725371592022,
'Bajo Stress (D)': 0.2529157606770202,
'Bajo Stress (I)': -0.0981237735359993,
'Bajo Stress (S)': 1.0,
'Bajo Stress (C)': -0.3570697743190169,
'span': -0.23885238917830093,
'Mean Team Performance': 0.41404235485716345,
'employment span': 0.33146618322475935,
'Pay to team size ratio': 0.49978958145813196},
'Bajo Stress (C)': {'Características (D)': -0.0461134826855843,
'Características (I)': -0.26492408476089707,
'Características (S)': -0.4698328671560004,
'Características (C)': 0.7732581689662739,
'Motivación (D)': 0.2698254124168881,
'Motivación (I)': -0.1236088717264958,
'Motivación (S)': -0.3091698232697242,
'Motivación (C)': 0.21452556505271267,
'Bajo Stress (D)': -0.31055770095686547,
'Bajo Stress (I)': -0.27961420029017486,
'Bajo Stress (S)': -0.3570697743190169,
'Bajo Stress (C)': 1.0,
'span': -0.01344626398272969,
'Mean Team Performance': -0.08070306908833835,
'employment span': -0.5968535698213163,
'Pay to team size ratio': -0.2795657757692292},
'span': {'Características (D)': 0.2874881163983965,
'Características (I)': -0.2923189384010105,
'Características (S)': -0.02087671997992093,
'Características (C)': 0.03775247426826095,
'Motivación (D)': 0.5037240436882805,
'Motivación (I)': -0.4334332491868192,
'Motivación (S)': 0.1503231802207429,
'Motivación (C)': 0.15796613914842977,
'Bajo Stress (D)': -0.11631187918782246,
'Bajo Stress (I)': -0.06711566955045667,
'Bajo Stress (S)': -0.23885238917830093,
'Bajo Stress (C)': -0.01344626398272969,
'span': 1.0,
'Mean Team Performance': -0.19851531030268585,
'employment span': 0.13994502995917002,
'Pay to team size ratio': -0.802380461421258},
'Mean Team Performance': {'Características (D)': 0.40633858242603244,
'Características (I)': -0.04150083345671622,
'Características (S)': -0.12496266913575294,
'Características (C)': -0.07825282894287325,
'Motivación (D)': 0.48414442720369955,
'Motivación (I)': -0.027223644357210867,
'Motivación (S)': -0.38838798587565976,
'Motivación (C)': -0.11411844367303944,
'Bajo Stress (D)': 0.05369401779765192,
'Bajo Stress (I)': 0.06327392392569486,
'Bajo Stress (S)': 0.41404235485716345,
'Bajo Stress (C)': -0.08070306908833835,
'span': -0.19851531030268585,
'Mean Team Performance': 1.0,
'employment span': 0.3992240651662481,
'Pay to team size ratio': 0.38910257451919805},
'employment span': {'Características (D)': -0.09857697245687172,
'Características (I)': 0.4006484556146567,
'Características (S)': 0.27001694775950746,
'Características (C)': -0.5003613024138532,
'Motivación (D)': -0.20711331594020507,
'Motivación (I)': 0.08277408562811393,
'Motivación (S)': 0.09981399691805137,
'Motivación (C)': -0.1335403092401566,
'Bajo Stress (D)': -0.042901905999867325,
'Bajo Stress (I)': 0.5471491483201977,
'Bajo Stress (S)': 0.33146618322475935,
'Bajo Stress (C)': -0.5968535698213163,
'span': 0.13994502995917002,
'Mean Team Performance': 0.3992240651662481,
'employment span': 1.0,
'Pay to team size ratio': 0.04572394154746432},
'Pay to team size ratio': {'Características (D)': 0.022958588188126107,
'Características (I)': 0.27081339758378836,
'Características (S)': 0.07931062556531454,
'Características (C)': -0.20937248430293648,
'Motivación (D)': -0.3769998767635495,
'Motivación (I)': 0.30770777808996924,
'Motivación (S)': -0.20858825983296703,
'Motivación (C)': -0.16110863218572585,
'Bajo Stress (D)': 0.4484652828139771,
'Bajo Stress (I)': 0.17612214868518486,
'Bajo Stress (S)': 0.49978958145813196,
'Bajo Stress (C)': -0.2795657757692292,
'span': -0.802380461421258,
'Mean Team Performance': 0.38910257451919805,
'employment span': 0.04572394154746432,
'Pay to team size ratio': 1.0}}
这是运行我的代码时热图的快照:
解决方案
您可以使用布局的yaxis_nticks
属性指定要显示的刻度数。
例如,数据帧中有多少行就可以有多少个刻度。
corr_fig.update_layout(title="Correlation heatmap",
yaxis={"title": 'Traits'},
xaxis={"title": 'Traits',"tickangle": 45},
yaxis_nticks=len(supervisor))
它呈现为
相关文章