{"id":4005,"date":"2023-07-14T05:45:40","date_gmt":"2023-07-14T05:45:40","guid":{"rendered":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/"},"modified":"2023-07-14T05:45:40","modified_gmt":"2023-07-14T05:45:40","slug":"seaborn-trama-diverse-righe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/","title":{"rendered":"Come disegnare pi\u00f9 linee in seaborn (con esempio)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare la seguente sintassi di base per disegnare pi\u00f9 linee sulla stessa trama utilizzando seaborn in Python:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <b><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\nsns. <span style=\"color: #3366ff;\">lineplot<\/span> (data=df[[' <span style=\"color: #ff0000;\">col1<\/span> ', ' <span style=\"color: #ff0000;\">col2<\/span> ', ' <span style=\"color: #ff0000;\">col3<\/span> ']]\n<\/b><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio creer\u00e0 un percorso con tre linee diverse.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: disegnare pi\u00f9 linee in Seaborn<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente DataFrame panda che contiene informazioni sulle vendite effettuate da quattro diversi negozi al dettaglio (A, B, C e D) per otto anni consecutivi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#createDataFrame\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">year<\/span> ': [1, 2, 3, 4, 5, 6, 7, 8],\n                   ' <span style=\"color: #ff0000;\">A<\/span> ': [10, 12, 14, 15, 15, 14, 13, 18],\n                   ' <span style=\"color: #ff0000;\">B<\/span> ': [18, 18, 19, 14, 14, 11, 20, 28],\n                   ' <span style=\"color: #ff0000;\">C<\/span> ': [5, 7, 7, 9, 12, 9, 9, 4],\n                   ' <span style=\"color: #ff0000;\">D<\/span> ': [11, 8, 10, 6, 6, 5, 9, 12]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   year ABCD\n0 1 10 18 5 11\n1 2 12 18 7 8\n2 3 14 19 7 10\n3 4 15 14 9 6\n4 5 15 14 12 6\n5 6 14 11 9 5\n6 7 13 20 9 9\n7 8 18 28 4 12\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la funzione <strong>lineplot()<\/strong> di Seaborn per creare un grafico che visualizzi quattro linee per rappresentare le vendite effettuate da ciascun negozio durante ogni anno:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#plot sales of each store as a line\n<\/span>sns. <span style=\"color: #3366ff;\">lineplot<\/span> (data=df[[' <span style=\"color: #ff0000;\">A<\/span> ',' <span style=\"color: #ff0000;\">B<\/span> ',' <span style=\"color: #ff0000;\">C<\/span> ',' <span style=\"color: #ff0000;\">D<\/span> ']])\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-32023\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/se1.jpg\" alt=\"trama marina multilinea\" width=\"529\" height=\"398\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Ogni riga rappresenta i valori di uno dei quattro negozi.<\/span><\/p>\n<p> <span style=\"color: #000000;\">La legenda nell&#8217;angolo in alto a sinistra indica quale colore corrisponde a quale negozio.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Nota che possiamo anche usare l&#8217;argomento <strong>palette<\/strong> per specificare i nostri colori da usare nella trama:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#plot sales of each store with custom colors\n<\/span>sns. <span style=\"color: #3366ff;\">lineplot<\/span> (data=df[[' <span style=\"color: #ff0000;\">A<\/span> ', ' <span style=\"color: #ff0000;\">B<\/span> ', ' <span style=\"color: #ff0000;\">C<\/span> ', ' <span style=\"color: #ff0000;\">D<\/span> ']], palette=[' <span style=\"color: #ff0000;\">red<\/span> ', ' <span style=\"color: #ff0000;\">blue<\/span> ', ' <span style=\"color: #ff0000;\">purple<\/span> ', ' <span style=\"color: #ff0000;\">pink<\/span> '])<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-32024 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/se2.jpg\" alt=\"\" width=\"516\" height=\"397\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Nota che i colori delle righe ora corrispondono ai quattro colori specificati nell&#8217;argomento <strong>palette<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se vuoi che ciascuna linea sia solida, puoi utilizzare la funzione pandas <strong>melt()<\/strong> per fondere DataFrame in un <a href=\"https:\/\/statorials.org\/it\/dati-lunghi-vs-dati-ampi\/\" target=\"_blank\" rel=\"noopener\">formato lungo<\/a> , quindi utilizzare la seguente sintassi per disegnare le linee:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#plot sales of each store with custom colors\n<\/span>sns. <span style=\"color: #3366ff;\">lineplot<\/span> (x=' <span style=\"color: #ff0000;\">year<\/span> ', y=' <span style=\"color: #ff0000;\">value<\/span> ', hue=' <span style=\"color: #ff0000;\">variable<\/span> ', \n             data=pd. <span style=\"color: #3366ff;\">melt<\/span> (df,[' <span style=\"color: #ff0000;\">year<\/span> ']),\n             palette=[' <span style=\"color: #ff0000;\">red<\/span> ', ' <span style=\"color: #ff0000;\">blue<\/span> ', ' <span style=\"color: #ff0000;\">purple<\/span> ', ' <span style=\"color: #ff0000;\">pink<\/span> '])\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-32025 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/se3.jpg\" alt=\"\" width=\"524\" height=\"405\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Ognuna delle linee ora \u00e8 continua invece di avere il proprio stile di linea.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : se hai difficolt\u00e0 a importare seaborn in un notebook Jupyter, potrebbe essere necessario eseguire prima il comando <strong>%pip install seaborn<\/strong> .<\/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 Seaborn:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/titolo-marino\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere un titolo alle trame di Seaborn<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/dimensione-del-font\/\" target=\"_blank\" rel=\"noopener\">Come modificare la dimensione del carattere nei grafici Seaborn<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/dimensione-della-figura-del-mare\/\" target=\"_blank\" rel=\"noopener\">Come regolare la dimensione della figura di una trama Seaborn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare la seguente sintassi di base per disegnare pi\u00f9 linee sulla stessa trama utilizzando seaborn in Python: import seaborn as sns sns. lineplot (data=df[[&#8216; col1 &#8216;, &#8216; col2 &#8216;, &#8216; col3 &#8216;]] Questo particolare esempio creer\u00e0 un percorso con tre linee diverse. L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica. Esempio: disegnare pi\u00f9 [&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 disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con 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\/seaborn-trama-diverse-righe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T05:45:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/se1.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\/seaborn-trama-diverse-righe\/\",\"url\":\"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/\",\"name\":\"Come disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-14T05:45:40+00:00\",\"dateModified\":\"2023-07-14T05:45:40+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come disegnare pi\u00f9 linee in seaborn (con esempio)\"}]},{\"@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 disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials","description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con 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\/seaborn-trama-diverse-righe\/","og_locale":"it_IT","og_type":"article","og_title":"Come disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials","og_description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con un esempio.","og_url":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/","og_site_name":"Statorials","article_published_time":"2023-07-14T05:45:40+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/se1.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\/seaborn-trama-diverse-righe\/","url":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/","name":"Come disegnare pi\u00f9 linee in Seaborn (con esempio) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-14T05:45:40+00:00","dateModified":"2023-07-14T05:45:40+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un unico tracciato in Seaborn, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/seaborn-trama-diverse-righe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come disegnare pi\u00f9 linee in seaborn (con esempio)"}]},{"@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\/4005"}],"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=4005"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4005\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}