{"id":2871,"date":"2023-07-20T08:04:01","date_gmt":"2023-07-20T08:04:01","guid":{"rendered":"https:\/\/statorials.org\/nl\/matplotlib-aline\/"},"modified":"2023-07-20T08:04:01","modified_gmt":"2023-07-20T08:04:01","slug":"matplotlib-aline","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/matplotlib-aline\/","title":{"rendered":"Hoe de abline-functie in matplotlib te gebruiken"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De <a href=\"https:\/\/statorials.org\/nl\/ablijn-in-r\/\" target=\"_blank\" rel=\"noopener\">abline-<\/a> functie in R kan worden gebruikt om een rechte lijn aan een pad toe te voegen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Helaas bestaat deze functie niet in Matplotlib, maar we kunnen de volgende functie defini\u00ebren om de abline-functie in Python te repliceren:<\/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<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008000;\">def<\/span> <span style=\"color: #0000ff;\">abline<\/span> (slope, intercept):\n    axes = plt. <span style=\"color: #3366ff;\">gca<\/span> ()\n    x_vals = np. <span style=\"color: #3366ff;\">array<\/span> ( <span style=\"color: #3366ff;\">axes.get_xlim<\/span> ())\n    y_vals = intercept + slope * x_vals\n    plt. <span style=\"color: #3366ff;\">plot<\/span> (x_vals, y_vals, '--')\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe u deze syntaxis in de praktijk kunt gebruiken met de volgende panda&#8217;s DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><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;\">x<\/span> ': [1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11],\n                   ' <span style=\"color: #ff0000;\">y<\/span> ': [13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40]})\n\n<span style=\"color: #008080;\">#view first five rows of DataFrame\n<\/span>df. <span style=\"color: #3366ff;\">head<\/span> ()\n\n\tx y\n0 1 13\n1 1 14\n2 2 17\n3 3 12\n4 4 23<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Abline gebruiken om een horizontale lijn te tekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen de volgende code gebruiken om een horizontale lijn te tekenen met de eerder gedefinieerde <strong>abline-<\/strong> functie:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> )\n\n<span style=\"color: #008080;\">#add horizontal line at y=30\n<\/span>abline( <span style=\"color: #008000;\">0,30<\/span> <span style=\"color: #008000;\">)<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-25090 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/abline1-1.jpg\" alt=\"\" width=\"566\" height=\"379\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Het resultaat is een horizontale lijn op y=30.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Gebruik aline om een lijn te tekenen met een specifieke helling en snijpunt<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen de volgende code gebruiken om een lijn te tekenen met een helling van <strong>3<\/strong> en een y-snijpunt van <strong>15<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> )\n\n<span style=\"color: #008080;\">#add straight line with slope=3 and intercept=15\n<\/span>abline( <span style=\"color: #008000;\">3,15<\/span> <span style=\"color: #008000;\">)<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-25092 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/abline3-1.jpg\" alt=\"\" width=\"541\" height=\"360\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Het resultaat is een rechte lijn met een helling van 3 en een snijpunt van 15.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 3: Gebruik abline om de regressielijn uit te zetten<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen de volgende code gebruiken om een regressielijn uit te zetten met de eerder gedefinieerde <strong>abline-<\/strong> functie:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate slope and intercept of regression line\n<span style=\"color: #000000;\">slope = np. <span style=\"color: #3366ff;\">polyfit<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> , 1)[ <span style=\"color: #008000;\">0<\/span> ]<\/span>\n<span style=\"color: #000000;\">intercept = np. <span style=\"color: #3366ff;\">polyfit<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> , 1)[ <span style=\"color: #008000;\">1<\/span> ]<\/span>\n\n#create scatterplot\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> )\n\n<span style=\"color: #008080;\">#add regression line\n<\/span><span style=\"color: #000000;\">abline(slope, intercept)<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-25091 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/abline2-1.jpg\" alt=\"\" width=\"544\" height=\"362\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Het resultaat is een aangepaste regressielijn die rechtstreeks door de plotpunten loopt.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : u kunt <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.polyfit.html\" target=\"_blank\" rel=\"noopener\">hier<\/a> de volledige documentatie van de <strong>polyfit-<\/strong> functie in NumPy vinden.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in panda&#8217;s kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/pandas-specifieke-somkolommen\/\" target=\"_blank\" rel=\"noopener\">Hoe specifieke kolommen in Panda&#8217;s op te tellen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-somkolom-met-voorwaarde\/\" target=\"_blank\" rel=\"noopener\">Hoe kolommen op te tellen op basis van een voorwaarde in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-omgekeerde-cumsum\/\" target=\"_blank\" rel=\"noopener\">Hoe een omgekeerde cumulatieve som in panda&#8217;s te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De abline- functie in R kan worden gebruikt om een rechte lijn aan een pad toe te voegen. Helaas bestaat deze functie niet in Matplotlib, maar we kunnen de volgende functie defini\u00ebren om de abline-functie in Python te repliceren: import matplotlib. pyplot as plt import numpy as np def abline (slope, intercept): axes = plt. [&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-2871","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 de abline-functie in Matplotlib \u2013 Statorials te gebruiken<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.\" \/>\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-aline\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de abline-functie in Matplotlib \u2013 Statorials te gebruiken\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/matplotlib-aline\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T08:04:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/abline1-1.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-aline\/\",\"url\":\"https:\/\/statorials.org\/nl\/matplotlib-aline\/\",\"name\":\"Hoe de abline-functie in Matplotlib \u2013 Statorials te gebruiken\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-20T08:04:01+00:00\",\"dateModified\":\"2023-07-20T08:04:01+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-aline\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/matplotlib-aline\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-aline\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de abline-functie in matplotlib te gebruiken\"}]},{\"@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 de abline-functie in Matplotlib \u2013 Statorials te gebruiken","description":"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.","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-aline\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de abline-functie in Matplotlib \u2013 Statorials te gebruiken","og_description":"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/matplotlib-aline\/","og_site_name":"Statorials","article_published_time":"2023-07-20T08:04:01+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/abline1-1.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-aline\/","url":"https:\/\/statorials.org\/nl\/matplotlib-aline\/","name":"Hoe de abline-functie in Matplotlib \u2013 Statorials te gebruiken","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-20T08:04:01+00:00","dateModified":"2023-07-20T08:04:01+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de functie abline in Matplotlib kunt maken, vergelijkbaar met de functie die in R wordt gebruikt, met een voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/matplotlib-aline\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/matplotlib-aline\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/matplotlib-aline\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de abline-functie in matplotlib te gebruiken"}]},{"@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\/2871","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=2871"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2871\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}