{"id":3567,"date":"2023-07-16T19:12:36","date_gmt":"2023-07-16T19:12:36","guid":{"rendered":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/"},"modified":"2023-07-16T19:12:36","modified_gmt":"2023-07-16T19:12:36","slug":"matplotlib-handbuchlegende","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/","title":{"rendered":"So erstellen sie eine manuelle legende in matplotlib (mit beispiel)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Sie k\u00f6nnen die Funktionen der Untermodule <strong>matplotlib.lines<\/strong> und <strong>matplotlib.patches<\/strong> verwenden, um eine manuelle Legende in einem Matplotlib-Plot zu erstellen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Das folgende Beispiel zeigt, wie das geht.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Beispiel: Erstellen Sie eine manuelle Legende in Matplotlib<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Der folgende Code zeigt, wie man in Matplotlib ein Streudiagramm mit einer Standardlegende erstellt:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><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;\">#define data to plot\n<\/span>x = [1, 2, 3, 4, 5, 6, 7]\ny = [2, 3, 5, 8, 12, 18, 27]\n\n<span style=\"color: #008080;\">#create scatter plot of x vs. y\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (x, y, label=' <span style=\"color: #ff0000;\">Original Data<\/span> ', color=' <span style=\"color: #ff0000;\">steelblue<\/span> ')\n\n<span style=\"color: #008080;\">#add legend\n<\/span>plt. <span style=\"color: #3366ff;\">legend<\/span> ()\n\n<span style=\"color: #008080;\">#displayplot\n<\/span>plt. <span style=\"color: #3366ff;\">show<\/span> ()<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-29488 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/manuel1.jpg\" alt=\"\" width=\"482\" height=\"367\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Um eine manuelle Legende mit benutzerdefinierten Linien und Quadraten zu erstellen, m\u00fcssen wir die Untermodule <strong>matplotlib.lines<\/strong> und <strong>matplotlib.patches<\/strong> importieren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Der folgende Code zeigt, wie diese Submodule zum Erstellen einer manuellen Legende verwendet werden:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><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<span style=\"color: #008000;\">from<\/span> matplotlib. <span style=\"color: #3366ff;\">lines<\/span> <span style=\"color: #008000;\">import<\/span> Line2D\n<span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">patches<\/span> <span style=\"color: #008000;\">as<\/span> mpatches\n\n<span style=\"color: #008080;\">#define data to plot\n<\/span>x = [1, 2, 3, 4, 5, 6, 7]\ny = [2, 3, 5, 8, 12, 18, 27]\n\n<span style=\"color: #008080;\">#create scatter plot of x vs. y\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (x, y, label=' <span style=\"color: #ff0000;\">Original Data<\/span> ', color=' <span style=\"color: #ff0000;\">steelblue<\/span> ')\n\n<span style=\"color: #008080;\">#define handles and labels that will get added to legend\n<\/span>handles, labels = plt. <span style=\"color: #3366ff;\">gca<\/span> (). <span style=\"color: #3366ff;\">get_legend_handles_labels<\/span> ()\n\n<span style=\"color: #008080;\">#define patches and lines to add to legend\n<\/span>patch1 = mpatches. <span style=\"color: #3366ff;\">Patch<\/span> (color=' <span style=\"color: #ff0000;\">orange<\/span> ', label=' <span style=\"color: #ff0000;\">First Manual Patch<\/span> ')\npatch2 = mpatches. <span style=\"color: #3366ff;\">Patch<\/span> (color=' <span style=\"color: #ff0000;\">orange<\/span> ', label=' <span style=\"color: #ff0000;\">First Manual Patch<\/span> ')   \nline1 = Line2D([0], [0], label=' <span style=\"color: #ff0000;\">First Manual Line<\/span> ', color=' <span style=\"color: #ff0000;\">purple<\/span> ')\nline2 = Line2D([0], [0], label=' <span style=\"color: #ff0000;\">Second Manual Line<\/span> ', color=' <span style=\"color: #ff0000;\">red<\/span> ')\n\n<span style=\"color: #008080;\">#add handles\n<\/span>handles. <span style=\"color: #3366ff;\">extend<\/span> ([patch1, line1, line2])\n\n<span style=\"color: #008080;\">#add legend\n<\/span>plt. <span style=\"color: #3366ff;\">legend<\/span> (handles=handles)\n\n<span style=\"color: #008080;\">#displayplot\n<\/span>plt. <span style=\"color: #3366ff;\">show<\/span> ()<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-29490\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/manuel2.jpg\" alt=\"Legende des Matplotlib-Handbuchs\" width=\"530\" height=\"400\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Beachten Sie, dass diese Legende die Beschriftung der Originaldaten, aber auch die Beschriftungen und Formen der Elemente enth\u00e4lt, die wir manuell hinzugef\u00fcgt haben.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Um die Beschriftungen oder Farben eines der Elemente zu \u00e4ndern, \u00e4ndern Sie einfach die Werte der <strong>Beschriftungs-<\/strong> und <strong>Farbargumente<\/strong> im vorherigen Codeabschnitt.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Hinweis<\/strong> : In <a href=\"https:\/\/statorials.org\/de\/matplotlib-legendenposition\/\" target=\"_blank\" rel=\"noopener\">diesem Tutorial<\/a> erfahren Sie, wie Sie die Position der Legende im Diagramm \u00e4ndern.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Zus\u00e4tzliche Ressourcen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Die folgenden Tutorials erkl\u00e4ren, wie Sie andere h\u00e4ufige Aufgaben in Matplotlib ausf\u00fchren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/de\/matplotlib-erhoht-die-tracegrosse\/\" target=\"_blank\" rel=\"noopener\">So erh\u00f6hen Sie die Plotgr\u00f6\u00dfe in Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/matplotlib-titelposition\/\" target=\"_blank\" rel=\"noopener\">So passen Sie die Titelposition in Matplotlib an<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/matplotlib-legt-den-achsenbereich-fest\/\" target=\"_blank\" rel=\"noopener\">So legen Sie Achsenbereiche in Matplotlib fest<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sie k\u00f6nnen die Funktionen der Untermodule matplotlib.lines und matplotlib.patches verwenden, um eine manuelle Legende in einem Matplotlib-Plot zu erstellen. Das folgende Beispiel zeigt, wie das geht. Beispiel: Erstellen Sie eine manuelle Legende in Matplotlib Der folgende Code zeigt, wie man in Matplotlib ein Streudiagramm mit einer Standardlegende erstellt: import matplotlib. pyplot as plt #define data [&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>So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.\" \/>\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\/de\/matplotlib-handbuchlegende\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-16T19:12:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/manuel1.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 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/\",\"url\":\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/\",\"name\":\"So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-16T19:12:36+00:00\",\"dateModified\":\"2023-07-16T19:12:36+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So erstellen sie eine manuelle legende in matplotlib (mit beispiel)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/de\/#website\",\"url\":\"https:\/\/statorials.org\/de\/\",\"name\":\"Statorials\",\"description\":\"Ihr Leitfaden f\u00fcr statistische Kompetenz !\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de-DE\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\",\"name\":\"Dr. Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de-DE\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. Benjamin Anderson\"},\"description\":\"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen\",\"sameAs\":[\"https:\/\/statorials.org\/de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials","description":"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.","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\/de\/matplotlib-handbuchlegende\/","og_locale":"de_DE","og_type":"article","og_title":"So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials","og_description":"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.","og_url":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/","og_site_name":"Statorials","article_published_time":"2023-07-16T19:12:36+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/manuel1.jpg"}],"author":"Dr. Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr. Benjamin Anderson","Gesch\u00e4tzte Lesezeit":"2 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/","url":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/","name":"So erstellen Sie eine manuelle Legende in Matplotlib (mit Beispiel) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-16T19:12:36+00:00","dateModified":"2023-07-16T19:12:36+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird anhand eines Beispiels erl\u00e4utert, wie Sie eine manuelle Legende in Matplotlib erstellen.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/matplotlib-handbuchlegende\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So erstellen sie eine manuelle legende in matplotlib (mit beispiel)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/de\/#website","url":"https:\/\/statorials.org\/de\/","name":"Statorials","description":"Ihr Leitfaden f\u00fcr statistische Kompetenz !","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de-DE"},{"@type":"Person","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0","name":"Dr. Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"de-DE","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Dr. Benjamin Anderson"},"description":"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen","sameAs":["https:\/\/statorials.org\/de"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/3567"}],"collection":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/comments?post=3567"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/3567\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=3567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=3567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=3567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}