如何将图例放在Seaborn的热图之外

时间:2019-03-31 17:18:52

标签: python-3.x seaborn legend heatmap

我正在用seaborn创建一个热图,但是图例放置在热图中并隐藏了值。如何将其移到外面?我该如何抑制(删除)?

有关可重现的示例:

data60.to_json()
'{"confort":{"cluster_focus_paints":2.1544579859,"cluster_focus_floor":1.3862891738,"cluster_focus_bathroom":1.4154752234,"cluster_focus_storage":2.2430016863,"cluster_focus_tools":74.246749226,"cluster_focus_metal_hardware_et_al":2.0518886044,"cluster_focus_confort":4.733209675,"cluster_focus_light":1.4447368421,"cluster_focus_garden":1.7622674167,"cluster_focus_decoration":1.7819245774,"cluster_focus_wood":1.8301220295,"cluster_focus_construction_products":1.283279296,"cluster_focus_electrological":1.3437935272},"paints":{"cluster_focus_paints":5.2293136626,"cluster_focus_floor":2.9466880342,"cluster_focus_bathroom":2.9560113729,"cluster_focus_storage":3.6807757167,"cluster_focus_tools":2.439628483,"cluster_focus_metal_hardware_et_al":3.2680857875,"cluster_focus_confort":8.4387742989,"cluster_focus_light":66.0776035834,"cluster_focus_garden":2.742838598,"cluster_focus_decoration":6.0927178153,"cluster_focus_wood":5.016955684,"cluster_focus_construction_products":3.1356646596,"cluster_focus_electrological":3.0441622286},"storage":{"cluster_focus_paints":2.2989095574,"cluster_focus_floor":4.3107549858,"cluster_focus_bathroom":69.6864337937,"cluster_focus_storage":2.1225969646,"cluster_focus_tools":1.8731534719,"cluster_focus_metal_hardware_et_al":2.0434699104,"cluster_focus_confort":6.838151061,"cluster_focus_light":2.2684770437,"cluster_focus_garden":2.9180008654,"cluster_focus_decoration":1.2743823147,"cluster_focus_wood":2.648298009,"cluster_focus_construction_products":3.0903659101,"cluster_focus_electrological":2.6591151168},"floor":{"cluster_focus_paints":0.9372674792,"cluster_focus_floor":3.2943732194,"cluster_focus_bathroom":2.1092607636,"cluster_focus_storage":1.1545531197,"cluster_focus_tools":1.316054843,"cluster_focus_metal_hardware_et_al":1.3324903969,"cluster_focus_confort":4.3841964683,"cluster_focus_light":1.5468645017,"cluster_focus_garden":68.0977066205,"cluster_focus_decoration":1.8241872562,"cluster_focus_wood":2.0447655748,"cluster_focus_construction_products":2.4031496063,"cluster_focus_electrological":1.5519459238},"decoration":{"cluster_focus_paints":1.4849262348,"cluster_focus_floor":2.5047720798,"cluster_focus_bathroom":2.1816409423,"cluster_focus_storage":1.7290893761,"cluster_focus_tools":1.3105263158,"cluster_focus_metal_hardware_et_al":1.9894046095,"cluster_focus_confort":4.8445169907,"cluster_focus_light":2.1457446809,"cluster_focus_garden":3.1225876244,"cluster_focus_decoration":1.05526658,"cluster_focus_wood":2.0335902376,"cluster_focus_construction_products":64.3934691987,"cluster_focus_electrological":3.7004916018},"garden":{"cluster_focus_paints":4.8089159718,"cluster_focus_floor":3.2304843305,"cluster_focus_bathroom":3.6816003249,"cluster_focus_storage":4.6783305228,"cluster_focus_tools":3.634763379,"cluster_focus_metal_hardware_et_al":71.3700384123,"cluster_focus_confort":9.3890488203,"cluster_focus_light":4.4411534155,"cluster_focus_garden":3.7450021636,"cluster_focus_decoration":3.8933680104,"cluster_focus_wood":3.428002569,"cluster_focus_construction_products":5.5364057434,"cluster_focus_electrological":5.030192544},"bathroom":{"cluster_focus_paints":2.1627966645,"cluster_focus_floor":66.8866096866,"cluster_focus_bathroom":4.2785946385,"cluster_focus_storage":2.8108768971,"cluster_focus_tools":2.053869969,"cluster_focus_metal_hardware_et_al":2.5712868118,"cluster_focus_confort":7.6584211307,"cluster_focus_light":2.310862262,"cluster_focus_garden":5.3487667676,"cluster_focus_decoration":1.956046814,"cluster_focus_wood":3.2099550417,"cluster_focus_construction_products":4.6998610468,"cluster_focus_electrological":4.1847193773},"tools":{"cluster_focus_paints":61.7813983323,"cluster_focus_floor":1.815491453,"cluster_focus_bathroom":1.741226645,"cluster_focus_storage":4.2418212479,"cluster_focus_tools":2.2922158337,"cluster_focus_metal_hardware_et_al":2.5132522407,"cluster_focus_confort":6.414438344,"cluster_focus_light":3.9615341545,"cluster_focus_garden":1.7777152748,"cluster_focus_decoration":3.5149544863,"cluster_focus_wood":3.4357096981,"cluster_focus_construction_products":1.5734599352,"cluster_focus_electrological":2.2761982794},"electrological":{"cluster_focus_paints":4.333867864,"cluster_focus_floor":2.4466168091,"cluster_focus_bathroom":2.2233956133,"cluster_focus_storage":62.7702360877,"cluster_focus_tools":2.6545776205,"cluster_focus_metal_hardware_et_al":3.0306017926,"cluster_focus_confort":6.7885888114,"cluster_focus_light":3.1559350504,"cluster_focus_garden":1.8509303332,"cluster_focus_decoration":2.6123537061,"cluster_focus_wood":2.8688503532,"cluster_focus_construction_products":2.1735062529,"cluster_focus_electrological":4.2029905776},"construction_products":{"cluster_focus_paints":1.1893521488,"cluster_focus_floor":0.5278846154,"cluster_focus_bathroom":0.5110073111,"cluster_focus_storage":0.9017706577,"cluster_focus_tools":0.8861565679,"cluster_focus_metal_hardware_et_al":0.928553137,"cluster_focus_confort":2.1832912895,"cluster_focus_light":1.639193729,"cluster_focus_garden":0.9470791865,"cluster_focus_decoration":66.6724317295,"cluster_focus_wood":1.5451509313,"cluster_focus_construction_products":0.4306160259,"cluster_focus_electrological":0.3735354363},"metal_hardware":{"cluster_focus_paints":4.9313021167,"cluster_focus_floor":2.4869301994,"cluster_focus_bathroom":2.7828188465,"cluster_focus_storage":3.2613827993,"cluster_focus_tools":1.7675807165,"cluster_focus_metal_hardware_et_al":2.3316901408,"cluster_focus_confort":15.5197952218,"cluster_focus_light":3.6452407615,"cluster_focus_garden":1.7577672003,"cluster_focus_decoration":2.4032509753,"cluster_focus_wood":5.6064226076,"cluster_focus_construction_products":2.9694766095,"cluster_focus_electrological":2.6074149939},"wood":{"cluster_focus_paints":2.7882617062,"cluster_focus_floor":1.5806980057,"cluster_focus_bathroom":1.7417140536,"cluster_focus_storage":1.6767284992,"cluster_focus_tools":1.4820875719,"cluster_focus_metal_hardware_et_al":1.2962868118,"cluster_focus_confort":5.0618341,"cluster_focus_light":2.0270996641,"cluster_focus_garden":1.8737775855,"cluster_focus_decoration":2.3676202861,"cluster_focus_wood":61.2712909441,"cluster_focus_construction_products":1.5410375174,"cluster_focus_electrological":1.1376075379},"children":{"cluster_focus_paints":0.2168697883,"cluster_focus_floor":0.1508190883,"cluster_focus_bathroom":0.1523558083,"cluster_focus_storage":0.2547217538,"cluster_focus_tools":0.0707651482,"cluster_focus_metal_hardware_et_al":0.2567861716,"cluster_focus_confort":0.2320373943,"cluster_focus_light":0.2235722284,"cluster_focus_garden":0.0783210731,"cluster_focus_decoration":0.0737321196,"cluster_focus_wood":0.1023121387,"cluster_focus_construction_products":0.2029180176,"cluster_focus_electrological":0.2363785334},"plumber_heat":{"cluster_focus_paints":2.1703014753,"cluster_focus_floor":1.9026709402,"cluster_focus_bathroom":1.2181153534,"cluster_focus_storage":2.7267284992,"cluster_focus_tools":1.4064130916,"cluster_focus_metal_hardware_et_al":1.0602112676,"cluster_focus_confort":9.1434485829,"cluster_focus_light":1.4956326988,"cluster_focus_garden":0.8487234963,"cluster_focus_decoration":2.1087126138,"cluster_focus_wood":1.7507385999,"cluster_focus_construction_products":0.632746642,"cluster_focus_electrological":0.9430151577},"light":{"cluster_focus_paints":3.511096857,"cluster_focus_floor":4.5286324786,"cluster_focus_bathroom":3.3216490658,"cluster_focus_storage":5.7481450253,"cluster_focus_tools":2.5659442724,"cluster_focus_metal_hardware_et_al":3.9532650448,"cluster_focus_confort":8.3699213533,"cluster_focus_light":3.6174132139,"cluster_focus_garden":3.1283427088,"cluster_focus_decoration":2.3690507152,"cluster_focus_wood":3.2078998073,"cluster_focus_construction_products":5.9337193145,"cluster_focus_electrological":66.7083572306}}'

sns.heatmap(data60.round(), annot = True, cmap = 'Blues')
plt.title('Percent of Total Spending of the non-Professional Customers within Each Product Focused Cluster/Segment \n\
in each of the Product Categories (1st Level Hierarchy)')
plt.xlabel('Product Category')
plt.ylabel('Product Focused Cluster/Segment')
plt.legend(title = 'Percent of Total Spending')

enter image description here

0 个答案:

没有答案