{"id":4205,"date":"2023-07-12T21:21:13","date_gmt":"2023-07-12T21:21:13","guid":{"rendered":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/"},"modified":"2023-07-12T21:21:13","modified_gmt":"2023-07-12T21:21:13","slug":"ggplot-in-stile-matplotlib","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/","title":{"rendered":"Come utilizzare gli stili ggplot nei grafici matplotlib"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Uno dei pacchetti di visualizzazione dati pi\u00f9 popolari nel linguaggio di programmazione R \u00e8 <strong>ggplot2<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Per applicare lo stile ggplot2 a un grafico creato in Matplotlib, puoi utilizzare la seguente sintassi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\nplt. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">use<\/span> (' <span style=\"color: #ff0000;\">ggplot<\/span> ')\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: utilizzo degli stili ggplot nei grafici Matplotlib<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Diciamo di avere un array NumPy con 1000 valori:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#make this example reproducible.\n<\/span>n.p. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">seed<\/span> ( <span style=\"color: #008000;\">1<\/span> )\n\n<span style=\"color: #008080;\">#create numpy array with 1000 values that follows normal dist with mean=10 and sd=2\n<\/span>data = np. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">normal<\/span> (size= <span style=\"color: #008000;\">1000<\/span> , loc= <span style=\"color: #008000;\">10<\/span> , scale= <span style=\"color: #008000;\">2<\/span> )\n\n<span style=\"color: #008080;\">#view first five values\n<\/span>data[: <span style=\"color: #008000;\">5<\/span> ]\n\narray([13.24869073, 8.77648717, 8.9436565, 7.85406276, 11.73081526])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per creare un istogramma in Matplotlib per visualizzare la distribuzione dei valori nell&#8217;array NumPy:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\"><span style=\"color: #000000;\"><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;\">#create histogram\n<\/span>plt. <span style=\"color: #3366ff;\">hist<\/span> (data, color=' <span style=\"color: #ff0000;\">lightgreen<\/span> ', ec=' <span style=\"color: #ff0000;\">black<\/span> ', bins= <span style=\"color: #008000;\">15<\/span> )\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-33255 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/deploiement1.jpg\" alt=\"\" width=\"502\" height=\"368\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Per applicare lo stile ggplot2 a questo istogramma, possiamo usare <strong>plt.syle.use(&#8216;ggplot&#8217;)<\/strong> come segue:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\"><span style=\"color: #000000;\"><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;\">#specify ggplot2 style\n<\/span>plt. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">use<\/span> (' <span style=\"color: #ff0000;\">ggplot<\/span> ')\n\n<span style=\"color: #008080;\">#create histogram with ggplot2 style\n<\/span>plt. <span style=\"color: #3366ff;\">hist<\/span> (data, color=' <span style=\"color: #ff0000;\">lightgreen<\/span> ', ec=' <span style=\"color: #ff0000;\">black<\/span> ', bins= <span style=\"color: #008000;\">15<\/span> )<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-33260\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/stylegg1.jpg\" alt=\"stile matplotib ggplot2\" width=\"547\" height=\"410\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;istogramma ora ha lo stile di un grafico creato in ggplot2.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vale a dire, questo stile aggiunge uno sfondo grigio chiaro con griglie bianche e utilizza etichette di graduazione degli assi leggermente pi\u00f9 grandi.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che abbiamo applicato lo stile ggplot2 a un istogramma, ma l&#8217;istruzione <strong>plt.style.use(&#8216;ggplot&#8217;)<\/strong> pu\u00f2 essere utilizzata per applicare lo stile ggplot2 a qualsiasi grafico in Matplotlib.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare altri fogli di stile disponibili per l&#8217;uso nei grafici Matplotlib <a href=\"https:\/\/matplotlib.org\/stable\/gallery\/style_sheets\/index.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/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 creare altri grafici comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/grafico-a-barre-in-pila-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Come creare grafici a barre in pila in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/istogramma-della-frequenza-relativa-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Come creare un istogramma di frequenza relativo in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/barplot-orizzontale-seaborn\/\" target=\"_blank\" rel=\"noopener\">Come creare un barplot orizzontale in Seaborn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uno dei pacchetti di visualizzazione dati pi\u00f9 popolari nel linguaggio di programmazione R \u00e8 ggplot2 . Per applicare lo stile ggplot2 a un grafico creato in Matplotlib, puoi utilizzare la seguente sintassi: import matplotlib. pyplot as plt plt. style . use (&#8216; ggplot &#8216;) L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica. Esempio: utilizzo [&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 gli stili ggplot nei grafici Matplotlib \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, 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\/ggplot-in-stile-matplotlib\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare gli stili ggplot nei grafici Matplotlib \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T21:21:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/deploiement1.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\/ggplot-in-stile-matplotlib\/\",\"url\":\"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/\",\"name\":\"Come utilizzare gli stili ggplot nei grafici Matplotlib \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-12T21:21:13+00:00\",\"dateModified\":\"2023-07-12T21:21:13+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare gli stili ggplot nei grafici 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 gli stili ggplot nei grafici Matplotlib \u2013 Statorials","description":"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, 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\/ggplot-in-stile-matplotlib\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare gli stili ggplot nei grafici Matplotlib \u2013 Statorials","og_description":"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, con un esempio.","og_url":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/","og_site_name":"Statorials","article_published_time":"2023-07-12T21:21:13+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/deploiement1.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\/ggplot-in-stile-matplotlib\/","url":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/","name":"Come utilizzare gli stili ggplot nei grafici Matplotlib \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-12T21:21:13+00:00","dateModified":"2023-07-12T21:21:13+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come applicare uno stile ggplot ai grafici in Matplotlib, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ggplot-in-stile-matplotlib\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare gli stili ggplot nei grafici 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\/4205"}],"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=4205"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4205\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}