{"id":4205,"date":"2023-07-12T21:21:13","date_gmt":"2023-07-12T21:21:13","guid":{"rendered":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/"},"modified":"2023-07-12T21:21:13","modified_gmt":"2023-07-12T21:21:13","slug":"matplotlib-stijl-ggplot","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/","title":{"rendered":"Hoe ggplot-stijlen te gebruiken in matplotlib-plots"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een van de meest populaire datavisualisatiepakketten in de programmeertaal R is <strong>ggplot2<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om de ggplot2-stijl toe te passen op een plot gemaakt in Matplotlib, kunt u de volgende syntaxis gebruiken:<\/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;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: ggplot-stijlen gebruiken in Matplotlib-plots<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat we een NumPy-array hebben met 1000 waarden:<\/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;\">We kunnen de volgende code gebruiken om een histogram in Matplotlib te maken om de verdeling van waarden in de NumPy-array te visualiseren:<\/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=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Om de ggplot2-stijl op dit histogram toe te passen, kunnen we <strong>plt.syle.use(&#8218;ggplot&#8216;)<\/strong> als volgt gebruiken:<\/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=\"matplotib ggplot2-stijl\" width=\"547\" height=\"410\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Het histogram heeft nu de stijl van een plot gemaakt in ggplot2.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze stijl voegt namelijk een lichtgrijze achtergrond toe met witte rasterlijnen en gebruikt iets grotere as-tick-labels.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Merk op dat we de ggplot2-stijl op een histogram hebben toegepast, maar de instructie <strong>plt.style.use(&#8218;ggplot&#8216;)<\/strong> kan worden gebruikt om de ggplot2-stijl op elke plot in Matplotlib toe te passen.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : <a href=\"https:\/\/matplotlib.org\/stable\/gallery\/style_sheets\/index.html\" target=\"_blank\" rel=\"noopener\">Hier<\/a> vindt u andere stylesheets die beschikbaar zijn voor gebruik in Matplotlib-plots.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere algemene diagrammen in Python kunt maken:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/matplotlib-gestapeld-staafdiagram\/\" target=\"_blank\" rel=\"noopener\">Hoe gestapelde staafdiagrammen te maken in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/matplotlib-relatieve-frequentiehistogram\/\" target=\"_blank\" rel=\"noopener\">Hoe u een relatief frequentiehistogram maakt in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/zeegeboren-horizontale-barplot\/\" target=\"_blank\" rel=\"noopener\">Hoe maak je een horizontaal staafdiagram in Seaborn?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een van de meest populaire datavisualisatiepakketten in de programmeertaal R is ggplot2 . Om de ggplot2-stijl toe te passen op een plot gemaakt in Matplotlib, kunt u de volgende syntaxis gebruiken: import matplotlib. pyplot as plt plt. style . use (&#8218; ggplot &#8218;) Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk [&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":[],"class_list":["post-4205","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.\" \/>\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\/nl\/matplotlib-stijl-ggplot\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/\" \/>\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=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/\",\"url\":\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/\",\"name\":\"Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-12T21:21:13+00:00\",\"dateModified\":\"2023-07-12T21:21:13+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe ggplot-stijlen te gebruiken in matplotlib-plots\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials","description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.","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\/nl\/matplotlib-stijl-ggplot\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials","og_description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.","og_url":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/","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":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/","url":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/","name":"Hoe ggplot-stijlen te gebruiken in Matplotlib-plots - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-12T21:21:13+00:00","dateModified":"2023-07-12T21:21:13+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u een ggplot-stijl kunt toepassen op plots in Matplotlib.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/matplotlib-stijl-ggplot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe ggplot-stijlen te gebruiken in matplotlib-plots"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=4205"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4205\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=4205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=4205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=4205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}