Emm*_*Emm 6 python pandas plotly plotly-dash
我用热图构建了一个仪表板。但是我注意到 t=我的 y 轴中的一些标签没有显示。我只得到了有限的我不知道出了什么问题。这是我的仪表板:
\n\nimport dash\nimport dash_table\nimport plotly.graph_objs as go\nimport dash_html_components as html\nimport dash_core_components as dcc\nfrom dash.dependencies import Input,Output\nimport pandas as pd\nimport os\nimport numpy as np\n#correlation dataframe\ncorrelation_df = supervisor[[\'Caracter\xc3\xadsticas (D)\', \'Caracter\xc3\xadsticas (I)\',\n \'Caracter\xc3\xadsticas (S)\', \'Caracter\xc3\xadsticas (C)\', \'Motivaci\xc3\xb3n (D)\',\n \'Motivaci\xc3\xb3n (I)\', \'Motivaci\xc3\xb3n (S)\', \'Motivaci\xc3\xb3n (C)\', \'Bajo Stress (D)\',\n \'Bajo Stress (I)\', \'Bajo Stress (S)\', \'Bajo Stress (C)\',\'span\',\'Mean Team Performance\',\'employment span\',\'Pay to team size ratio\']]\ncorrelation_df = correlation_df.corr()\ncorr_fig = go.Figure()\ncorr_fig.add_trace(go.Heatmap(\n z= correlation_df.values,\n x= [\'Caracter\xc3\xadsticas (D)\', \'Caracter\xc3\xadsticas (I)\',\n \'Caracter\xc3\xadsticas (S)\', \'Caracter\xc3\xadsticas (C)\', \'Motivaci\xc3\xb3n (D)\',\n \'Motivaci\xc3\xb3n (I)\', \'Motivaci\xc3\xb3n (S)\', \'Motivaci\xc3\xb3n (C)\', \'Bajo Stress (D)\',\n \'Bajo Stress (I)\', \'Bajo Stress (S)\', \'Bajo Stress (C)\',\'span\',\'Mean Team Performance\',\'employment span\',\'Pay to team size ratio\'],\n y= [\'Caracter\xc3\xadsticas (D)\', \'Caracter\xc3\xadsticas (I)\',\n \'Caracter\xc3\xadsticas (S)\', \'Caracter\xc3\xadsticas (C)\', \'Motivaci\xc3\xb3n (D)\',\n \'Motivaci\xc3\xb3n (I)\', \'Motivaci\xc3\xb3n (S)\', \'Motivaci\xc3\xb3n (C)\', \'Bajo Stress (D)\',\n \'Bajo Stress (I)\', \'Bajo Stress (S)\', \'Bajo Stress (C)\',\'span\',\'Mean Team Performance\',\'employment span\',\'Pay to team size ratio\'],\n hoverongaps=False\n))\ncorr_fig.update_layout(title="Correlation heatmap",\n yaxis={"title": \'Traits\'},\n xaxis={"title": \'Traits\',"tickangle": 45}, )\napp = dash.Dash()\n#html layout\napp.layout = html.Div(children=[\n html.H1(children=\'Dashboard\', style={\n \'textAlign\': \'center\',\n \'height\': \'10\'\n }),\n dcc.Graph(\n id=\'heatmap\',\n figure=corr_fig.to_dict()\n )\n ])\nif __name__ == \'__main__\':\n app.run_server(debug=True)\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的数据框的示例:
\n\n{\'Caracter\xc3\xadsticas (D)\': {\'Caracter\xc3\xadsticas (D)\': 1.0,\n \'Caracter\xc3\xadsticas (I)\': -0.744432853713455,\n \'Caracter\xc3\xadsticas (S)\': 0.20085563028990697,\n \'Caracter\xc3\xadsticas (C)\': -0.039907357919985106,\n \'Motivaci\xc3\xb3n (D)\': 0.8232188768568326,\n \'Motivaci\xc3\xb3n (I)\': -0.6987940156295481,\n \'Motivaci\xc3\xb3n (S)\': 0.17336394623619988,\n \'Motivaci\xc3\xb3n (C)\': -0.03941838984936696,\n \'Bajo Stress (D)\': 0.8142337605566142,\n \'Bajo Stress (I)\': -0.48861318810993065,\n \'Bajo Stress (S)\': 0.3207614659369065,\n \'Bajo Stress (C)\': -0.0461134826855843,\n \'span\': 0.2874881163983965,\n \'Mean Team Performance\': 0.40633858242603244,\n \'employment span\': -0.09857697245687172,\n \'Pay to team size ratio\': 0.022958588188126107},\n \'Caracter\xc3\xadsticas (I)\': {\'Caracter\xc3\xadsticas (D)\': -0.744432853713455,\n \'Caracter\xc3\xadsticas (I)\': 1.0,\n \'Caracter\xc3\xadsticas (S)\': -0.3779100652350093,\n \'Caracter\xc3\xadsticas (C)\': -0.11879176229148546,\n \'Motivaci\xc3\xb3n (D)\': -0.8454566900924195,\n \'Motivaci\xc3\xb3n (I)\': 0.8314885901746485,\n \'Motivaci\xc3\xb3n (S)\': -0.5493813305976118,\n \'Motivaci\xc3\xb3n (C)\': 0.020902885445784,\n \'Bajo Stress (D)\': -0.4614762821424876,\n \'Bajo Stress (I)\': 0.8628000011272827,\n \'Bajo Stress (S)\': 0.07723803992022794,\n \'Bajo Stress (C)\': -0.26492408476089707,\n \'span\': -0.2923189384010105,\n \'Mean Team Performance\': -0.04150083345671622,\n \'employment span\': 0.4006484556146567,\n \'Pay to team size ratio\': 0.27081339758378836},\n \'Caracter\xc3\xadsticas (S)\': {\'Caracter\xc3\xadsticas (D)\': 0.20085563028990697,\n \'Caracter\xc3\xadsticas (I)\': -0.3779100652350093,\n \'Caracter\xc3\xadsticas (S)\': 1.0,\n \'Caracter\xc3\xadsticas (C)\': -0.7739057580439489,\n \'Motivaci\xc3\xb3n (D)\': 0.28928161764191546,\n \'Motivaci\xc3\xb3n (I)\': -0.14811042351159115,\n \'Motivaci\xc3\xb3n (S)\': 0.7823864767779756,\n \'Motivaci\xc3\xb3n (C)\': -0.6651182815949327,\n \'Bajo Stress (D)\': 0.10162624205618695,\n \'Bajo Stress (I)\': -0.5488737066087104,\n \'Bajo Stress (S)\': 0.46905181352171205,\n \'Bajo Stress (C)\': -0.4698328671560004,\n \'span\': -0.02087671997992093,\n \'Mean Team Performance\': -0.12496266913575294,\n \'employment span\': 0.27001694775950746,\n \'Pay to team size ratio\': 0.07931062556531454},\n \'Caracter\xc3\xadsticas (C)\': {\'Caracter\xc3\xadsticas (D)\': -0.039907357919985106,\n \'Caracter\xc3\xadsticas (I)\': -0.11879176229148546,\n \'Caracter\xc3\xadsticas (S)\': -0.7739057580439489,\n \'Caracter\xc3\xadsticas (C)\': 1.0,\n \'Motivaci\xc3\xb3n (D)\': -0.011616389427962759,\n \'Motivaci\xc3\xb3n (I)\': -0.292733356844308,\n \'Motivaci\xc3\xb3n (S)\': -0.4343733032773228,\n \'Motivaci\xc3\xb3n (C)\': 0.774357808826908,\n \'Bajo Stress (D)\': -0.04367706074639601,\n \'Bajo Stress (I)\': 0.0931714388059811,\n \'Bajo Stress (S)\': -0.6482541912883304,\n \'Bajo Stress (C)\': 0.7732581689662739,\n \'span\': 0.03775247426826095,\n \'Mean Team Performance\': -0.07825282894287325,\n \'employment span\': -0.5003613024138532,\n \'Pay to team size ratio\': -0.20937248430293648},\n \'Motivaci\xc3\xb3n (D)\': {\'Caracter\xc3\xadsticas (D)\': 0.8232188768568326,\n \'Caracter\xc3\xadsticas (I)\': -0.8454566900924195,\n \'Caracter\xc3\xadsticas (S)\': 0.28928161764191546,\n \'Caracter\xc3\xadsticas (C)\': -0.011616389427962759,\n \'Motivaci\xc3\xb3n (D)\': 1.0,\n \'Motivaci\xc3\xb3n (I)\': -0.6401977926528387,\n \'Motivaci\xc3\xb3n (S)\': 0.27806883694592277,\n \'Motivaci\xc3\xb3n (C)\': -0.2534345146499511,\n \'Bajo Stress (D)\': 0.35748019323906,\n \'Bajo Stress (I)\': -0.7219032007713697,\n \'Bajo Stress (S)\': 0.21293087519106632,\n \'Bajo Stress (C)\': 0.2698254124168881,\n \'span\': 0.5037240436882805,\n \'Mean Team Performance\': 0.48414442720369955,\n \'employment span\': -0.20711331594020507,\n \'Pay to team size ratio\': -0.3769998767635495},\n \'Motivaci\xc3\xb3n (I)\': {\'Caracter\xc3\xadsticas (D)\': -0.6987940156295481,\n \'Caracter\xc3\xadsticas (I)\': 0.8314885901746485,\n \'Caracter\xc3\xadsticas (S)\': -0.14811042351159115,\n \'Caracter\xc3\xadsticas (C)\': -0.292733356844308,\n \'Motivaci\xc3\xb3n (D)\': -0.6401977926528387,\n \'Motivaci\xc3\xb3n (I)\': 1.0,\n \'Motivaci\xc3\xb3n (S)\': -0.48288361435623983,\n \'Motivaci\xc3\xb3n (C)\': -0.4135335004412625,\n \'Bajo Stress (D)\': -0.5563645790627242,\n \'Bajo Stress (I)\': 0.45272622386580263,\n \'Bajo Stress (S)\': 0.31345796324782077,\n \'Bajo Stress (C)\': -0.1236088717264958,\n \'span\': -0.4334332491868192,\n \'Mean Team Performance\': -0.027223644357210867,\n \'employment span\': 0.08277408562811393,\n \'Pay to team size ratio\': 0.30770777808996924},\n \'Motivaci\xc3\xb3n (S)\': {\'Caracter\xc3\xadsticas (D)\': 0.17336394623619988,\n \'Caracter\xc3\xadsticas (I)\': -0.5493813305976118,\n \'Caracter\xc3\xadsticas (S)\': 0.7823864767779756,\n \'Caracter\xc3\xadsticas (C)\': -0.4343733032773228,\n \'Motivaci\xc3\xb3n (D)\': 0.27806883694592277,\n \'Motivaci\xc3\xb3n (I)\': -0.48288361435623983,\n \'Motivaci\xc3\xb3n (S)\': 1.0,\n \'Motivaci\xc3\xb3n (C)\': -0.23220036735524985,\n \'Bajo Stress (D)\': 0.12079023858043715,\n \'Bajo Stress (I)\': -0.5418626995091027,\n \'Bajo Stress (S)\': -0.12381340765657087,\n \'Bajo Stress (C)\': -0.3091698232697242,\n \'span\': 0.1503231802207429,\n \'Mean Team Performance\': -0.38838798587565976,\n \'employment span\': 0.09981399691805137,\n \'Pay to team size ratio\': -0.20858825983296703},\n \'Motivaci\xc3\xb3n (C)\': {\'Caracter\xc3\xadsticas (D)\': -0.03941838984936696,\n \'Caracter\xc3\xadsticas (I)\': 0.020902885445784,\n \'Caracter\xc3\xadsticas (S)\': -0.6651182815949327,\n \'Caracter\xc3\xadsticas (C)\': 0.774357808826908,\n \'Motivaci\xc3\xb3n (D)\': -0.2534345146499511,\n \'Motivaci\xc3\xb3n (I)\': -0.4135335004412625,\n \'Motivaci\xc3\xb3n (S)\': -0.23220036735524985,\n \'Motivaci\xc3\xb3n (C)\': 1.0,\n \'Bajo Stress (D)\': 0.18028688548066718,\n \'Bajo Stress (I)\': 0.386437402512207,\n \'Bajo Stress (S)\': -0.7351725371592022,\n \'Bajo Stress (C)\': 0.21452556505271267,\n \'span\': 0.15796613914842977,\n \'Mean Team Performance\': -0.11411844367303944,\n \'employment span\': -0.1335403092401566,\n \'Pay to team size ratio\': -0.16110863218572585},\n \'Bajo Stress (D)\': {\'Caracter\xc3\xadsticas (D)\': 0.8142337605566142,\n \'Caracter\xc3\xadsticas (I)\': -0.4614762821424876,\n \'Caracter\xc3\xadsticas (S)\': 0.10162624205618695,\n \'Caracter\xc3\xadsticas (C)\': -0.04367706074639601,\n \'Motivaci\xc3\xb3n (D)\': 0.35748019323906,\n \'Motivaci\xc3\xb3n (I)\': -0.5563645790627242,\n \'Motivaci\xc3\xb3n (S)\': 0.12079023858043715,\n \'Motivaci\xc3\xb3n (C)\': 0.18028688548066718,\n \'Bajo Stress (D)\': 1.0,\n \'Bajo Stress (I)\': -0.1849352428080063,\n \'Bajo Stress (S)\': 0.2529157606770202,\n \'Bajo Stress (C)\': -0.31055770095686547,\n \'span\': -0.11631187918782246,\n \'Mean Team Performance\': 0.05369401779765192,\n \'employment span\': -0.042901905999867325,\n \'Pay to team size ratio\': 0.4484652828139771},\n \'Bajo Stress (I)\': {\'Caracter\xc3\xadsticas (D)\': -0.48861318810993065,\n \'Caracter\xc3\xadsticas (I)\': 0.8628000011272827,\n \'Caracter\xc3\xadsticas (S)\': -0.5488737066087104,\n \'Caracter\xc3\xadsticas (C)\': 0.0931714388059811,\n \'Motivaci\xc3\xb3n (D)\': -0.7219032007713697,\n \'Motivaci\xc3\xb3n (I)\': 0.45272622386580263,\n \'Motivaci\xc3\xb3n (S)\': -0.5418626995091027,\n \'Motivaci\xc3\xb3n (C)\': 0.386437402512207,\n \'Bajo Stress (D)\': -0.1849352428080063,\n \'Bajo Stress (I)\': 1.0,\n \'Bajo Stress (S)\': -0.0981237735359993,\n \'Bajo Stress (C)\': -0.27961420029017486,\n \'span\': -0.06711566955045667,\n \'Mean Team Performance\': 0.06327392392569486,\n \'employment span\': 0.5471491483201977,\n \'Pay to team size ratio\': 0.17612214868518486},\n \'Bajo Stress (S)\': {\'Caracter\xc3\xadsticas (D)\': 0.3207614659369065,\n \'Caracter\xc3\xadsticas (I)\': 0.07723803992022794,\n \'Caracter\xc3\xadsticas (S)\': 0.46905181352171205,\n \'Caracter\xc3\xadsticas (C)\': -0.6482541912883304,\n \'Motivaci\xc3\xb3n (D)\': 0.21293087519106632,\n \'Motivaci\xc3\xb3n (I)\': 0.31345796324782077,\n \'Motivaci\xc3\xb3n (S)\': -0.12381340765657087,\n \'Motivaci\xc3\xb3n (C)\': -0.7351725371592022,\n \'Bajo Stress (D)\': 0.2529157606770202,\n \'Bajo Stress (I)\': -0.0981237735359993,\n \'Bajo Stress (S)\': 1.0,\n \'Bajo Stress (C)\': -0.3570697743190169,\n \'span\': -0.23885238917830093,\n \'Mean Team Performance\': 0.41404235485716345,\n \'employment span\': 0.33146618322475935,\n \'Pay to team size ratio\': 0.49978958145813196},\n \'Bajo Stress (C)\': {\'Caracter\xc3\xadsticas (D)\': -0.0461134826855843,\n \'Caracter\xc3\xadsticas (I)\': -0.26492408476089707,\n \'Caracter\xc3\xadsticas (S)\': -0.4698328671560004,\n \'Caracter\xc3\xadsticas (C)\': 0.7732581689662739,\n \'Motivaci\xc3\xb3n (D)\': 0.2698254124168881,\n \'Motivaci\xc3\xb3n (I)\': -0.1236088717264958,\n \'Motivaci\xc3\xb3n (S)\': -0.3091698232697242,\n \'Motivaci\xc3\xb3n (C)\': 0.21452556505271267,\n \'Bajo Stress (D)\': -0.31055770095686547,\n \'Bajo Stress (I)\': -0.27961420029017486,\n \'Bajo Stress (S)\': -0.3570697743190169,\n \'Bajo Stress (C)\': 1.0,\n \'span\': -0.01344626398272969,\n \'Mean Team Performance\': -0.08070306908833835,\n \'employment span\': -0.5968535698213163,\n \'Pay to team size ratio\': -0.2795657757692292},\n \'span\': {\'Caracter\xc3\xadsticas (D)\': 0.2874881163983965,\n \'Caracter\xc3\xadsticas (I)\': -0.2923189384010105,\n \'Caracter\xc3\xadsticas (S)\': -0.02087671997992093,\n \'Caracter\xc3\xadsticas (C)\': 0.03775247426826095,\n \'Motivaci\xc3\xb3n (D)\': 0.5037240436882805,\n \'Motivaci\xc3\xb3n (I)\': -0.4334332491868192,\n \'Motivaci\xc3\xb3n (S)\': 0.1503231802207429,\n \'Motivaci\xc3\xb3n (C)\': 0.15796613914842977,\n \'Bajo Stress (D)\': -0.11631187918782246,\n \'Bajo Stress (I)\': -0.06711566955045667,\n \'Bajo Stress (S)\': -0.23885238917830093,\n \'Bajo Stress (C)\': -0.01344626398272969,\n \'span\': 1.0,\n \'Mean Team Performance\': -0.19851531030268585,\n \'employment span\': 0.13994502995917002,\n \'Pay to team size ratio\': -0.802380461421258},\n \'Mean Team Performance\': {\'Caracter\xc3\xadsticas (D)\': 0.40633858242603244,\n \'Caracter\xc3\xadsticas (I)\': -0.04150083345671622,\n \'Caracter\xc3\xadsticas (S)\': -0.12496266913575294,\n \'Caracter\xc3\xadsticas (C)\': -0.07825282894287325,\n \'Motivaci\xc3\xb3n (D)\': 0.48414442720369955,\n \'Motivaci\xc3\xb3n (I)\': -0.027223644357210867,\n \'Motivaci\xc3\xb3n (S)\': -0.38838798587565976,\n \'Motivaci\xc3\xb3n (C)\': -0.11411844367303944,\n \'Bajo Stress (D)\': 0.05369401779765192,\n \'Bajo Stress (I)\': 0.06327392392569486,\n \'Bajo Stress (S)\': 0.41404235485716345,\n \'Bajo Stress (C)\': -0.08070306908833835,\n \'span\': -0.19851531030268585,\n \'Mean Team Performance\': 1.0,\n \'employment span\': 0.3992240651662481,\n \'Pay to team size ratio\': 0.38910257451919805},\n \'employment span\': {\'Caracter\xc3\xadsticas (D)\': -0.09857697245687172,\n \'Caracter\xc3\xadsticas (I)\': 0.4006484556146567,\n \'Caracter\xc3\xadsticas (S)\': 0.27001694775950746,\n \'Caracter\xc3\xadsticas (C)\': -0.5003613024138532,\n \'Motivaci\xc3\xb3n (D)\': -0.20711331594020507,\n \'Motivaci\xc3\xb3n (I)\': 0.08277408562811393,\n \'Motivaci\xc3\xb3n (S)\': 0.09981399691805137,\n \'Motivaci\xc3\xb3n (C)\': -0.1335403092401566,\n \'Bajo Stress (D)\': -0.042901905999867325,\n \'Bajo Stress (I)\': 0.5471491483201977,\n \'Bajo Stress (S)\': 0.33146618322475935,\n \'Bajo Stress (C)\': -0.5968535698213163,\n \'span\': 0.13994502995917002,\n \'Mean Team Performance\': 0.3992240651662481,\n \'employment span\': 1.0,\n \'Pay to team size ratio\': 0.04572394154746432},\n \'Pay to team size ratio\': {\'Caracter\xc3\xadsticas (D)\': 0.022958588188126107,\n \'Caracter\xc3\xadsticas (I)\': 0.27081339758378836,\n \'Caracter\xc3\xadsticas (S)\': 0.07931062556531454,\n \'Caracter\xc3\xadsticas (C)\': -0.20937248430293648,\n \'Motivaci\xc3\xb3n (D)\': -0.3769998767635495,\n \'Motivaci\xc3\xb3n (I)\': 0.30770777808996924,\n \'Motivaci\xc3\xb3n (S)\': -0.20858825983296703,\n \'Motivaci\xc3\xb3n (C)\': -0.16110863218572585,\n \'Bajo Stress (D)\': 0.4484652828139771,\n \'Bajo Stress (I)\': 0.17612214868518486,\n \'Bajo Stress (S)\': 0.49978958145813196,\n \'Bajo Stress (C)\': -0.2795657757692292,\n \'span\': -0.802380461421258,\n \'Mean Team Performance\': 0.38910257451919805,\n \'employment span\': 0.04572394154746432,\n \'Pay to team size ratio\': 1.0}}\nRun Code Online (Sandbox Code Playgroud)\n\n\n
您可以使用yaxis_nticks布局的属性来指定要显示的刻度数。
例如,您可以拥有与数据框中的行数一样多的刻度。
corr_fig.update_layout(title="Correlation heatmap",
yaxis={"title": 'Traits'},
xaxis={"title": 'Traits',"tickangle": 45},
yaxis_nticks=len(supervisor))
Run Code Online (Sandbox Code Playgroud)
因此,我能够通过增加热图的长度来解决这个问题。我假设由于热图的大小,一些 y 标签被剪掉
corr_fig.update_layout(title="Correlation heatmap",
yaxis={"title": 'Traits'},
width=1200,
height=1400,
xaxis={"title": 'Traits',"tickangle": 45}, )
Run Code Online (Sandbox Code Playgroud)