{"id":1832,"date":"2023-07-24T19:48:39","date_gmt":"2023-07-24T19:48:39","guid":{"rendered":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/"},"modified":"2023-07-24T19:48:39","modified_gmt":"2023-07-24T19:48:39","slug":"matplotlib-horizontale-lijn","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/","title":{"rendered":"Een horizontale lijn tekenen in matplotlib (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende syntaxis gebruiken om een horizontale lijn in Matplotlib te plotten:<\/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;\">#draw vertical line at y=10\n<\/span>plt. <span style=\"color: #3366ff;\">axhlin<\/span> (y=10)\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;\"> <span style=\"color: #000000;\"><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, 2, 3, 4, 5, 6, 7, 8],\n                   ' <span style=\"color: #ff0000;\">y<\/span> ': [5, 7, 8, 15, 26, 39, 45, 40]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span>df\n\n\tx y\n0 1 5\n1 2 7\n2 3 8\n3 4 15\n4 5 26\n5 6 39\n6 7 45\n7 8 40\n<\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: een horizontale lijn tekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u een horizontale lijn tekent op een Matplotlib-plot:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><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;\">#create line plot\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/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=10\n<\/span>plt. <span style=\"color: #3366ff;\">axhline<\/span> (y=10, color=' <span style=\"color: #ff0000;\">red<\/span> ', linestyle=' <span style=\"color: #ff0000;\">--<\/span> ')<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-17719\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/horiz1.png\" alt=\"Hoe teken je een horizontale lijn in Matplotlib?\" width=\"598\" height=\"416\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: meerdere horizontale lijnen tekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u meerdere horizontale lijnen tekent op een Matplotlib-plot:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><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;\">#create line plot\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/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=10\n<\/span>plt. <span style=\"color: #3366ff;\">axhline<\/span> (y=10, color=' <span style=\"color: #ff0000;\">red<\/span> ', linestyle=' <span style=\"color: #ff0000;\">--<\/span> ')\n\n<span style=\"color: #008080;\">#add horizontal line at y=30\n<\/span>plt. <span style=\"color: #3366ff;\">axhline<\/span> (y=30, color=' <span style=\"color: #ff0000;\">black<\/span> ', linestyle=' <span style=\"color: #ff0000;\">-<\/span> ')\n<\/strong><\/span><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-17720\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/horiz2.png\" alt=\"Meerdere horizontale lijnen in Matplotlib\" width=\"594\" height=\"416\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <strong>Voorbeeld 3: Teken meerdere horizontale lijnen met een legenda<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u meerdere horizontale lijnen tekent op een Matplotlib-plot en hoe u een legenda toevoegt om de lijnen gemakkelijker te kunnen interpreteren:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><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;\">#create line plot\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/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=10\n<\/span>plt. <span style=\"color: #3366ff;\">axhline<\/span> (y=10, color=' <span style=\"color: #ff0000;\">red<\/span> ', linestyle=' <span style=\"color: #ff0000;\">--<\/span> ', label=' <span style=\"color: #ff0000;\">First Line<\/span> ')\n\n<span style=\"color: #008080;\">#add horizontal line at y=30\n<\/span>plt. <span style=\"color: #3366ff;\">axhline<\/span> (y=30, color=' <span style=\"color: #ff0000;\">black<\/span> ', linestyle=' <span style=\"color: #ff0000;\">-<\/span> ', label=' <span style=\"color: #ff0000;\">Second Line<\/span> ')\n\n<span style=\"color: #008080;\">#add legend<\/span>\nplt. <span style=\"color: #3366ff;\">legend<\/span> ()<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-17721 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/horiz3.png\" alt=\"Horizontale lijnen in matplotlib met legenda\" width=\"597\" height=\"415\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking:<\/strong> Raadpleeg de <a href=\"https:\/\/matplotlib.org\/stable\/api\/_as_gen\/matplotlib.lines.Line2D.html\" target=\"_blank\" rel=\"noopener\">Matplotlib-documentatie<\/a> voor een volledige lijst met lijnkleuren en -stijlen die u op horizontale lijnen kunt toepassen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/verticale-lijn-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Hoe teken je een verticale lijn in Matplotlib?<\/a><br \/><a href=\"https:\/\/statorials.org\/nl\/plot-meerdere-lijnen-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Hoe meerdere lijnen in Matplotlib te plotten<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/matplotlib-tijdreeks\/\" target=\"_blank\" rel=\"noopener\">Hoe een tijdreeks in Matplotlib te plotten<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/rechthoek-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Hoe rechthoeken te tekenen in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/matplotlib-pijl\/\" target=\"_blank\" rel=\"noopener\">Hoe pijlen te tekenen in Matplotlib<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende syntaxis gebruiken om een horizontale lijn in Matplotlib te plotten: import matplotlib. pyplot as plt #draw vertical line at y=10 plt. axhlin (y=10) De volgende voorbeelden laten zien hoe u deze syntaxis in de praktijk kunt gebruiken met de volgende panda&#8217;s DataFrame: import pandas as pd #createDataFrame df = pd. DataFrame [&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-1832","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>Een horizontale lijn tekenen in Matplotlib (met voorbeelden)<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.\" \/>\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-horizontale-lijn\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Een horizontale lijn tekenen in Matplotlib (met voorbeelden)\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T19:48:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/horiz1.png\" \/>\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-horizontale-lijn\/\",\"url\":\"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/\",\"name\":\"Een horizontale lijn tekenen in Matplotlib (met voorbeelden)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-24T19:48:39+00:00\",\"dateModified\":\"2023-07-24T19:48:39+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Een horizontale lijn tekenen in matplotlib (met voorbeelden)\"}]},{\"@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":"Een horizontale lijn tekenen in Matplotlib (met voorbeelden)","description":"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.","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-horizontale-lijn\/","og_locale":"de_DE","og_type":"article","og_title":"Een horizontale lijn tekenen in Matplotlib (met voorbeelden)","og_description":"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/","og_site_name":"Statorials","article_published_time":"2023-07-24T19:48:39+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/horiz1.png"}],"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-horizontale-lijn\/","url":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/","name":"Een horizontale lijn tekenen in Matplotlib (met voorbeelden)","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-24T19:48:39+00:00","dateModified":"2023-07-24T19:48:39+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u een horizontale lijn aan Matplotlib-plots toevoegt, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/matplotlib-horizontale-lijn\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Een horizontale lijn tekenen in matplotlib (met voorbeelden)"}]},{"@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\/1832","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=1832"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1832\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}