{"id":1937,"date":"2023-07-24T09:23:30","date_gmt":"2023-07-24T09:23:30","guid":{"rendered":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/"},"modified":"2023-07-24T09:23:30","modified_gmt":"2023-07-24T09:23:30","slug":"wykres-gestosci-matplotlib","status":"publish","type":"post","link":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/","title":{"rendered":"Jak utworzy\u0107 wykres g\u0119sto\u015bci w matplotlib (z przyk\u0142adami)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Naj\u0142atwiejszym sposobem utworzenia wykresu g\u0119sto\u015bci w Matplotlib jest u\u017cycie funkcji <a href=\"https:\/\/seaborn.pydata.org\/generated\/seaborn.kdeplot.html\" target=\"_blank\" rel=\"noopener\">kdeplot()<\/a> z biblioteki wizualizacji seaborn:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#define data<\/span>\ndata = [value1, value2, value3, ...]\n\n<span style=\"color: #008080;\">#create density plot of data\n<\/span>sns. <span style=\"color: #3366ff;\">kdeplot<\/span> (data)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Poni\u017csze przyk\u0142ady pokazuj\u0105, jak w praktyce wykorzysta\u0107 t\u0119 funkcj\u0119.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Przyk\u0142ad 1: Utw\u00f3rz podstawowy wykres g\u0119sto\u015bci<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Poni\u017cszy kod pokazuje, jak utworzy\u0107 podstawowy wykres g\u0119sto\u015bci w Seaborn:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#define data<\/span>\ndata = [2, 2, 3, 5, 6, 6, 7, 8, 9, 10, 12, 12, 13, 15, 16]\n\n<span style=\"color: #008080;\">#create density plot of data\n<\/span>sns. <span style=\"color: #3366ff;\">kdeplot<\/span> (data)<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18449\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn1.png\" alt=\"dzia\u0142ka g\u0119sto\u015bci w Seaborn\" width=\"525\" height=\"373\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">O\u015b x pokazuje warto\u015bci danych, a o\u015b y pokazuje odpowiednie warto\u015bci g\u0119sto\u015bci prawdopodobie\u0144stwa.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Przyk\u0142ad 2: Regulacja g\u0142adko\u015bci wykresu g\u0119sto\u015bci<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Mo\u017cesz u\u017cy\u0107 argumentu <strong>bw_method<\/strong> , aby dostosowa\u0107 g\u0142adko\u015b\u0107 wykresu g\u0119sto\u015bci. Ni\u017csze warto\u015bci prowadz\u0105 do bardziej \u201efalistej\u201d \u015bcie\u017cki.<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#define data<\/span>\ndata = [2, 2, 3, 5, 6, 6, 7, 8, 9, 10, 12, 12, 13, 15, 16]\n\n<span style=\"color: #008080;\">#create density plot of data with low bw_method value\n<\/span>sns. <span style=\"color: #3366ff;\">kdeplot<\/span> (data, bw_method = <span style=\"color: #008000;\">.3<\/span> )<\/strong> <\/pre>\n<h3><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-18450 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn2.png\" alt=\"\" width=\"498\" height=\"360\" srcset=\"\" sizes=\"auto, \"><\/h3>\n<p> <span style=\"color: #000000;\">I odwrotnie, wy\u017csze warto\u015bci <strong>bw_method<\/strong> prowadz\u0105 do p\u0142ynniejszego wykresu:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#define data<\/span>\ndata = [2, 2, 3, 5, 6, 6, 7, 8, 9, 10, 12, 12, 13, 15, 16]\n\n<span style=\"color: #008080;\">#create density plot of data with high bw_method value\n<\/span>sns. <span style=\"color: #3366ff;\">kdeplot<\/span> (data, bw_method = <span style=\"color: #008000;\">.8<\/span> )<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-18451 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn3.png\" alt=\"\" width=\"532\" height=\"383\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Przyk\u0142ad 3: Dostosuj wykres g\u0119sto\u015bci<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Mo\u017cesz tak\u017ce dostosowa\u0107 kolor i styl wykresu g\u0119sto\u015bci:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> seaborn <span style=\"color: #008000;\">as<\/span> sns\n\n<span style=\"color: #008080;\">#define data<\/span>\ndata = [2, 2, 3, 5, 6, 6, 7, 8, 9, 10, 12, 12, 13, 15, 16]\n\n<span style=\"color: #008080;\">#create density plot of data with high bw_method value\n<\/span>sns. <span style=\"color: #3366ff;\">kdeplot<\/span> (data, color=' <span style=\"color: #ff0000;\">red<\/span> ', fill= <span style=\"color: #008000;\">True<\/span> , alpha= <span style=\"color: #008000;\">.3<\/span> , linewidth= <span style=\"color: #008000;\">0<\/span> )<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-18452 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn4.png\" alt=\"\" width=\"522\" height=\"368\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Dodatkowe zasoby<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pl\/krzywe-gestosci\/\" target=\"_blank\" rel=\"noopener\">Wprowadzenie do krzywych g\u0119sto\u015bci<\/a><br \/> <a href=\"https:\/\/statorials.org\/pl\/wykresl-wiele-linii-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Jak wykre\u015bli\u0107 wiele linii w Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/pl\/lista-histogramow-pythona\/\" target=\"_blank\" rel=\"noopener\">Jak wykre\u015bli\u0107 histogram z listy danych w Pythonie<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Naj\u0142atwiejszym sposobem utworzenia wykresu g\u0119sto\u015bci w Matplotlib jest u\u017cycie funkcji kdeplot() z biblioteki wizualizacji seaborn: import seaborn as sns #define data data = [value1, value2, value3, &#8230;] #create density plot of data sns. kdeplot (data) Poni\u017csze przyk\u0142ady pokazuj\u0105, jak w praktyce wykorzysta\u0107 t\u0119 funkcj\u0119. Przyk\u0142ad 1: Utw\u00f3rz podstawowy wykres g\u0119sto\u015bci Poni\u017cszy kod pokazuje, jak utworzy\u0107 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1937","post","type-post","status-publish","format-standard","hentry","category-przewodnik"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials<\/title>\n<meta name=\"description\" content=\"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.\" \/>\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\/pl\/wykres-gestosci-matplotlib\/\" \/>\n<meta property=\"og:locale\" content=\"pl_PL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials\" \/>\n<meta property=\"og:description\" content=\"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T09:23:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn1.png\" \/>\n<meta name=\"author\" content=\"Benjamin Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Napisane przez\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Szacowany czas czytania\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minuta\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/\",\"url\":\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/\",\"name\":\"Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pl\/#website\"},\"datePublished\":\"2023-07-24T09:23:30+00:00\",\"dateModified\":\"2023-07-24T09:23:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\"},\"description\":\"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/#breadcrumb\"},\"inLanguage\":\"pl-PL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Dom\",\"item\":\"https:\/\/statorials.org\/pl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Jak utworzy\u0107 wykres g\u0119sto\u015bci w matplotlib (z przyk\u0142adami)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pl\/#website\",\"url\":\"https:\/\/statorials.org\/pl\/\",\"name\":\"Statorials\",\"description\":\"Tw\u00f3j przewodnik po kompetencjach statystycznych!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pl-PL\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\",\"name\":\"Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pl-PL\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin Anderson\"},\"description\":\"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej\",\"sameAs\":[\"https:\/\/statorials.org\/pl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials","description":"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.","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\/pl\/wykres-gestosci-matplotlib\/","og_locale":"pl_PL","og_type":"article","og_title":"Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials","og_description":"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.","og_url":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/","og_site_name":"Statorials","article_published_time":"2023-07-24T09:23:30+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/densiteseaborn1.png"}],"author":"Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Napisane przez":"Benjamin Anderson","Szacowany czas czytania":"1 minuta"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/","url":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/","name":"Jak utworzy\u0107 wykres g\u0119sto\u015bci w Matplotlib (z przyk\u0142adami) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pl\/#website"},"datePublished":"2023-07-24T09:23:30+00:00","dateModified":"2023-07-24T09:23:30+00:00","author":{"@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965"},"description":"W tym samouczku wyja\u015bniono, jak tworzy\u0107 wykresy g\u0119sto\u015bci w Matplotlib, z kilkoma przyk\u0142adami.","breadcrumb":{"@id":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/#breadcrumb"},"inLanguage":"pl-PL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pl\/wykres-gestosci-matplotlib\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Dom","item":"https:\/\/statorials.org\/pl\/"},{"@type":"ListItem","position":2,"name":"Jak utworzy\u0107 wykres g\u0119sto\u015bci w matplotlib (z przyk\u0142adami)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pl\/#website","url":"https:\/\/statorials.org\/pl\/","name":"Statorials","description":"Tw\u00f3j przewodnik po kompetencjach statystycznych!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pl-PL"},{"@type":"Person","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965","name":"Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"pl-PL","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Benjamin Anderson"},"description":"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej","sameAs":["https:\/\/statorials.org\/pl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/1937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/comments?post=1937"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/1937\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/media?parent=1937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/categories?post=1937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/tags?post=1937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}