{"id":4213,"date":"2023-07-12T19:52:17","date_gmt":"2023-07-12T19:52:17","guid":{"rendered":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/"},"modified":"2023-07-12T19:52:17","modified_gmt":"2023-07-12T19:52:17","slug":"matplotilb-tight_layout","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/","title":{"rendered":"Come utilizzare tight_layout() in matplotlib"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la funzione <strong>Tight_layout()<\/strong> in Matplotlib per regolare automaticamente il riempimento tra e attorno alle sottotrame.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa funzione nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: come utilizzare Tight_layout() in Matplotlib<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di utilizzare Matplotilb per creare quattro sottotrame in una griglia 2&#215;2:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#define data\n<\/span>x = [1, 2, 3]\ny = [7, 13, 24]\n\n<span style=\"color: #008080;\">#define layout for subplots\n<\/span>fig, ax = plt. <span style=\"color: #3366ff;\">subplots<\/span> (2, 2)\n\n<span style=\"color: #008080;\">#define subplot titles\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">red<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">blue<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">green<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">purple<\/span> ')\n\n<span style=\"color: #008080;\">#add title to each subplot\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">First Subplot<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Second Subplot<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Third Subplot<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Fourth Subplot<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-33315 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/serre1.jpg\" alt=\"\" width=\"466\" height=\"369\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;imbottitura tra le sottotrame \u00e8 minima, con conseguente sovrapposizione dei titoli in alcuni punti.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Specificando <strong>fig.tight_layout()<\/strong> possiamo regolare automaticamente il riempimento tra e attorno alle sottotrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#define data\n<\/span>x = [1, 2, 3]\ny = [7, 13, 24]\n\n<span style=\"color: #008080;\">#define layout for subplots\n<\/span>fig, ax = plt. <span style=\"color: #3366ff;\">subplots<\/span> (2, 2)\n\n<span style=\"color: #008080;\">#specify a tight layout<\/span>\nfig. <span style=\"color: #3366ff;\">tight_layout<\/span> ()\n\n<span style=\"color: #008080;\">#define subplot titles\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">red<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">blue<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">green<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">purple<\/span> ')\n\n<span style=\"color: #008080;\">#add title to each subplot\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">First Subplot<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Second Subplot<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Third Subplot<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Fourth Subplot<\/span> ')<\/strong><\/pre>\n<p> <strong><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-33316\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/serre2.jpg\" alt=\"Esempio di matplotlib tight_layout\" width=\"531\" height=\"421\" srcset=\"\" sizes=\"\"><\/strong><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che il riempimento tra e attorno alle sottotrame \u00e8 stato regolato in modo che le trame non si sovrappongano pi\u00f9 in nessuna area.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Si noti che la funzione <strong>Tight_layout()<\/strong> accetta un argomento <strong>pad<\/strong> per specificare il riempimento tra il bordo della figura e i bordi del sottopercorso, come frazione della dimensione del carattere.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Il valore <strong>del pad<\/strong> predefinito \u00e8 <strong>1.08<\/strong> . Tuttavia, possiamo aumentare questo valore per aumentare il riempimento attorno ai percorsi:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#define data\n<\/span>x = [1, 2, 3]\ny = [7, 13, 24]\n\n<span style=\"color: #008080;\">#define layout for subplots\n<\/span>fig, ax = plt. <span style=\"color: #3366ff;\">subplots<\/span> (2, 2)\n\n<span style=\"color: #008080;\">#specify a tight layout with increased padding<\/span>\nfig. <span style=\"color: #3366ff;\">tight_layout<\/span> (pad=5)\n\n<span style=\"color: #008080;\">#define subplot titles\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">red<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">blue<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">green<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">plot<\/span> (x,y,color=' <span style=\"color: #ff0000;\">purple<\/span> ')\n\n<span style=\"color: #008080;\">#add title to each subplot\n<\/span>ax[0, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">First Subplot<\/span> ')\nax[0, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Second Subplot<\/span> ')\nax[1, 0]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Third Subplot<\/span> ')\nax[1, 1]. <span style=\"color: #3366ff;\">set_title<\/span> (' <span style=\"color: #ff0000;\">Fourth Subplot<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-33317\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/serre3.jpg\" alt=\"Matplotlib Tight_layout con imbottitura aumentata\" width=\"526\" height=\"379\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Si noti che il riempimento attorno ai lotti \u00e8 aumentato notevolmente.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Sentiti libero di regolare il valore dell&#8217;argomento <strong>pad<\/strong> per aumentare quanto vuoi il riempimento attorno ai percorsi.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in Matplotlib:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/titolo-della-sottotrama-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere un titolo alle sottotrame in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/dimensione-della-sottotrama-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Come regolare la dimensione della sottotrama in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/spaziatura-della-sottotrama-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Come regolare la spaziatura tra le sottotrame Matplotlib<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la funzione Tight_layout() in Matplotlib per regolare automaticamente il riempimento tra e attorno alle sottotrame. L&#8217;esempio seguente mostra come utilizzare questa funzione nella pratica. Esempio: come utilizzare Tight_layout() in Matplotlib Supponiamo di utilizzare Matplotilb per creare quattro sottotrame in una griglia 2&#215;2: import matplotlib. pyplot as plt #define data x = [1, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T19:52:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/serre1.jpg\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/\",\"url\":\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/\",\"name\":\"Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-12T19:52:17+00:00\",\"dateModified\":\"2023-07-12T19:52:17+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare tight_layout() in matplotlib\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials","description":"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials","og_description":"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.","og_url":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/","og_site_name":"Statorials","article_published_time":"2023-07-12T19:52:17+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/serre1.jpg"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/","url":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/","name":"Come utilizzare Tight_layout() in Matplotlib \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-12T19:52:17+00:00","dateModified":"2023-07-12T19:52:17+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare Tight_layout in Matplotilb per creare pi\u00f9 grafici con un riempimento ottimale, incluso un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/matplotilb-tight_layout\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/matplotilb-tight_layout\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare tight_layout() in matplotlib"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4213"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=4213"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4213\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}