{"id":1659,"date":"2023-07-25T11:56:30","date_gmt":"2023-07-25T11:56:30","guid":{"rendered":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/"},"modified":"2023-07-25T11:56:30","modified_gmt":"2023-07-25T11:56:30","slug":"deret-waktu-matplotlib","status":"publish","type":"post","link":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/","title":{"rendered":"Cara membuat plot deret waktu di matplotlib (dengan contoh)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Anda dapat menggunakan sintaks berikut untuk memplot deret waktu di Matplotlib:<\/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\nplt. <span style=\"color: #3366ff;\">plot<\/span> (df. <span style=\"color: #3366ff;\">x<\/span> , df. <span style=\"color: #3366ff;\">y<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Ini mengasumsikan bahwa variabel x termasuk dalam kelas <strong>datetime.datetime()<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Contoh berikut menunjukkan cara menggunakan sintaks ini untuk memplot data deret waktu dengan Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Contoh 1: Plot deret waktu dasar di Matplotlib<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Kode berikut menunjukkan cara memplot deret waktu di Matplotlib yang menunjukkan total penjualan yang dilakukan oleh bisnis selama 12 hari berturut-turut:<\/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> datetime\n<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#define data\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">date<\/span> ': np. <span style=\"color: #3366ff;\">array<\/span> ([datetime. <span style=\"color: #3366ff;\">datetime<\/span> (2020, 1, i+1)\n<span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(12)]),\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [3, 4, 4, 7, 8, 9, 14, 17, 12, 8, 8, 13]})\n\n<span style=\"color: #008080;\">#plot time series\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> (df. <span style=\"color: #3366ff;\">date<\/span> , df. <span style=\"color: #3366ff;\">sales<\/span> , linewidth= <span style=\"color: #008000;\">3<\/span> )<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-16349 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/heure1.png\" alt=\"\" width=\"556\" height=\"388\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Sumbu X menunjukkan tanggal dan sumbu Y menunjukkan total penjualan pada setiap tanggal.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Contoh 2: Sesuaikan label judul dan sumbu<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Anda dapat menggunakan kode berikut untuk menambahkan judul dan label sumbu ke plot:<\/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> datetime\n<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#define data\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">date<\/span> ': np. <span style=\"color: #3366ff;\">array<\/span> ([datetime. <span style=\"color: #3366ff;\">datetime<\/span> (2020, 1, i+1)\n<span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(12)]),\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [3, 4, 4, 7, 8, 9, 14, 17, 12, 8, 8, 13]})\n\n<span style=\"color: #008080;\">#plot time series\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> (df. <span style=\"color: #3366ff;\">date<\/span> , df. <span style=\"color: #3366ff;\">sales<\/span> , linewidth= <span style=\"color: #008000;\">3<\/span> )\n\n<span style=\"color: #008080;\">#add title and axis labels\n<\/span>plt. <span style=\"color: #3366ff;\">title<\/span> (' <span style=\"color: #ff0000;\">Sales by Date<\/span> ')\nplt. <span style=\"color: #3366ff;\">xlabel<\/span> (' <span style=\"color: #ff0000;\">Date<\/span> ')\nplt. <span style=\"color: #3366ff;\">ylabel<\/span> (' <span style=\"color: #ff0000;\">Sales<\/span> ')\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-16352 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/heure2.png\" alt=\"\" width=\"558\" height=\"401\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Contoh 3: Plot beberapa deret waktu di Matplotlib<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Kode berikut menunjukkan cara memplot beberapa deret waktu dalam satu plot di Matplotlib:<\/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<span style=\"color: #008000;\">import<\/span> datetime\n<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#define data\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">date<\/span> ': np. <span style=\"color: #3366ff;\">array<\/span> ([datetime. <span style=\"color: #3366ff;\">datetime<\/span> (2020, 1, i+1)\n                                     <span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(12)]),\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [3, 4, 4, 7, 8, 9, 14, 17, 12, 8, 8, 13]})\n\ndf2 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">date<\/span> ': np. <span style=\"color: #3366ff;\">array<\/span> ([datetime. <span style=\"color: #3366ff;\">datetime<\/span> (2020, 1, i+1)\n                                      <span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(12)]),\n                   ' <span style=\"color: #ff0000;\">returns<\/span> ': [1, 1, 2, 3, 3, 3, 4, 3, 2, 3, 4, 7]})\n\n<span style=\"color: #008080;\">#plot both time series\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> ( <span style=\"color: #3366ff;\">df.date<\/span> , <span style=\"color: #3366ff;\">df.sales<\/span> , label=' <span style=\"color: #ff0000;\">sales<\/span> ', linewidth= <span style=\"color: #008000;\">3<\/span> )\nplt. <span style=\"color: #3366ff;\">plot<\/span> ( <span style=\"color: #3366ff;\">df2.date<\/span> , <span style=\"color: #3366ff;\">df2.returns<\/span> , color=' <span style=\"color: #ff0000;\">red<\/span> ', label=' <span style=\"color: #ff0000;\">returns<\/span> ', linewidth= <span style=\"color: #008000;\">3<\/span> )\n\n<span style=\"color: #008080;\">#add title and axis labels\n<\/span>plt. <span style=\"color: #3366ff;\">title<\/span> (' <span style=\"color: #ff0000;\">Sales by Date<\/span> ')\nplt. <span style=\"color: #3366ff;\">xlabel<\/span> (' <span style=\"color: #ff0000;\">Date<\/span> ')\nplt. <span style=\"color: #3366ff;\">ylabel<\/span> (' <span style=\"color: #ff0000;\">Sales<\/span> ')\n\n<span style=\"color: #008080;\">#add legend<\/span>\nplt. <span style=\"color: #3366ff;\">legend<\/span> ()\n\n<span style=\"color: #008080;\">#displayplot\n<\/span>plt. <span style=\"color: #3366ff;\">show<\/span> ()<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-16353 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/temps3.png\" alt=\"Beberapa deret waktu di Matplotlib\" width=\"578\" height=\"415\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Sumber daya tambahan<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/id\/matplotlib-boxplot-berdasarkan-grup\/\" target=\"_blank\" rel=\"noopener\">Matplotlib: Cara membuat plot kotak berdasarkan grup<\/a><br \/> <a href=\"https:\/\/statorials.org\/id\/diagram-batang-bertumpuk-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Matplotlib: Cara Membuat Diagram Batang Bertumpuk<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anda dapat menggunakan sintaks berikut untuk memplot deret waktu di Matplotlib: import matplotlib. pyplot as plt plt. plot (df. x , df. y ) Ini mengasumsikan bahwa variabel x termasuk dalam kelas datetime.datetime() . Contoh berikut menunjukkan cara menggunakan sintaks ini untuk memplot data deret waktu dengan Python. Contoh 1: Plot deret waktu dasar di [&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>Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)<\/title>\n<meta name=\"description\" content=\"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.\" \/>\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\/id\/deret-waktu-matplotlib\/\" \/>\n<meta property=\"og:locale\" content=\"id_ID\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)\" \/>\n<meta property=\"og:description\" content=\"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T11:56:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/heure1.png\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Ditulis oleh\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimasi waktu membaca\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 menit\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/\",\"url\":\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/\",\"name\":\"Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/id\/#website\"},\"datePublished\":\"2023-07-25T11:56:30+00:00\",\"dateModified\":\"2023-07-25T11:56:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81\"},\"description\":\"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/#breadcrumb\"},\"inLanguage\":\"id\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/statorials.org\/id\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cara membuat plot deret waktu di matplotlib (dengan contoh)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/id\/#website\",\"url\":\"https:\/\/statorials.org\/id\/\",\"name\":\"Statorials\",\"description\":\"Panduan anda untuk kompetensi statistik!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/id\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"id\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"id\",\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Halo, saya Benjamin, pensiunan profesor statistika yang menjadi guru Statorial yang berdedikasi. Dengan pengalaman dan keahlian yang luas di bidang statistika, saya ingin berbagi ilmu untuk memberdayakan mahasiswa melalui Statorials. Baca selengkapnya\",\"sameAs\":[\"http:\/\/statorials.org\/id\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)","description":"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.","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\/id\/deret-waktu-matplotlib\/","og_locale":"id_ID","og_type":"article","og_title":"Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)","og_description":"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.","og_url":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/","og_site_name":"Statorials","article_published_time":"2023-07-25T11:56:30+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/heure1.png"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Ditulis oleh":"Benjamin anderson","Estimasi waktu membaca":"2 menit"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/","url":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/","name":"Cara Membuat Plot Deret Waktu di Matplotlib (dengan Contoh)","isPartOf":{"@id":"https:\/\/statorials.org\/id\/#website"},"datePublished":"2023-07-25T11:56:30+00:00","dateModified":"2023-07-25T11:56:30+00:00","author":{"@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81"},"description":"Tutorial ini menjelaskan cara memplot deret waktu di Matplotlib, dengan beberapa contoh.","breadcrumb":{"@id":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/#breadcrumb"},"inLanguage":"id","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/id\/deret-waktu-matplotlib\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/statorials.org\/id\/"},{"@type":"ListItem","position":2,"name":"Cara membuat plot deret waktu di matplotlib (dengan contoh)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/id\/#website","url":"https:\/\/statorials.org\/id\/","name":"Statorials","description":"Panduan anda untuk kompetensi statistik!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/id\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"id"},{"@type":"Person","@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"id","@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Halo, saya Benjamin, pensiunan profesor statistika yang menjadi guru Statorial yang berdedikasi. Dengan pengalaman dan keahlian yang luas di bidang statistika, saya ingin berbagi ilmu untuk memberdayakan mahasiswa melalui Statorials. Baca selengkapnya","sameAs":["http:\/\/statorials.org\/id"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts\/1659"}],"collection":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/comments?post=1659"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts\/1659\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/media?parent=1659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/categories?post=1659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/tags?post=1659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}