首页 > 解决方案 > 相关矩阵在左上水平块和左下水平块中缺少一个类别的半个切片

问题描述

下矩阵请你能帮我理解为什么我的二维矩阵相关图的顶部和底部都被切掉了。

矩阵左上角的时髦角落

矩阵左下角的时髦角落

data1 = {'basic_cotton_ultra': [-1779046585, -1745487915, -1745369611, -1753758211, -1753790979, -1753916035, -1758110339, -1753776833, -1754176225, -1779337953, -1779337953, -1796083425, -1795958913, -1661806721, -1107830785, -1108017153, -1082857513, -1082857515, -1082666537, -1082699265, -1082699281, -1116269057, -1117448705, -1653136257, -1653119873, -1644989089, -1645128417, -1645185761, -1661864673, -1661731041, -1644691681 , -1611143331, -1619663011, -1636445347, -1636318243, -1627926019, -1611278867, -1619730963, -1623949841, -1623888513, -162592516065, -16858]

'celosia_velvet': [-194646179, -194904257, -1268529857, -1267481313, -1250822825, -1208752313, -1225529513, -1225694361, -1234144793, -1234173465, -1216936713, -143180577, -168346147, -50914817, -51176481, -588169249, -588224545, -596577313, -596520097, -579741929, -546244841, -537860265, -554637481, -554506905, -554512153, -697057049, -680312579, -713829155, -713822883, -730600611, -731776387, -194904449 , -194972065, -194783457, -193740513, -176962273, -143403233, -160301257, -697176265, -697047753, -160214985, -159956865, -159956739],

'woven_wallpaper': [-1757944449, -1754017481, -1754017515, -1779175147, -1779043531, -1779042771, -1779042771, -1787437443, -1787298211, -1753743393, -1216487969, -1208099362, -1208101634, -1208617730, -1217006338, -1217006338, -1753747330, -1754009569, -1787596515, -1787727555, -1796116164, -1796114644, -1778942356, -1778950531, -1787330859, -1753219385, -1753227306, -1753360938, -1753360898, -1744833058, -1753745954, -1753877122 , -1753947778, -1754140353, -1754050275, -1644990083, -1645120131, -1663993988, -1663598723, -1671995683, -1655218467, -1653034097, -1625]

 data = pd.DataFrame(data1, columns = ["basic_cotton_ultra","celosia_velvet","chiffon","cotton_poplin_ultra","cotton_spandex_jersey","cotton_twill","cyress_cotton_canvas","eco-cotton","fleece","kona_cotton_ultra","lightweight_cotton_twill","linen_cotton_canvas_ultra","long_leaf_sateen_grand","milky","modern_jersey","organic_cotton_knit_ultra","organic_cotton_sateen_ultra","perennial_green_grand","performance_pique","poly_crepe_de_chine","sateen","silkyfaile","sport_lycra","woven_wallpaper",])

 corr = data.corr()
 fig = plt.figure(figsize=(18,18))
 ax = fig.add_subplot(111)
 cax = ax.matshow(corr, cmap='coolwarm', vmin=-1, vmax=1)
 fig.colorbar(cax)
 ticks = np.arange(0,len(data.columns),1)
 ax.set_xticks(ticks)
 plt.xticks(rotation=90)
 ax.set_yticks(ticks)
 ax.set_xticklabels(data.columns)
 ax.set_yticklabels(data.columns)
 #plt.title("Correlation Matrix")
 plt.savefig('Correlation_Matrix.png')
 plt.show()

所有的正方形应该是相同的大小。基本棉超是红色矩形,编织壁纸是灰色矩形。

提前致谢

使用 ax.get_ylim() 后的矩阵顶部

标签: pythonpandasmatplotlibplot

解决方案


推荐阅读