{"id":2405,"date":"2023-07-22T10:17:48","date_gmt":"2023-07-22T10:17:48","guid":{"rendered":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/"},"modified":"2023-07-22T10:17:48","modified_gmt":"2023-07-22T10:17:48","slug":"matplotlib-on-line","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/","title":{"rendered":"Como usar \u201c%matplotlib online\u201d (com exemplos)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar o c\u00f3digo a seguir para exibir e armazenar gr\u00e1ficos <a href=\"https:\/\/matplotlib.org\/\" target=\"_blank\" rel=\"noopener\">Matplotlib<\/a> em um notebook Python Jupyter:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #800080;\">%<\/span> matplotlib inline\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Veja como esse c\u00f3digo \u00e9 descrito na <a href=\"https:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/plotting.html\" target=\"_blank\" rel=\"noopener\">p\u00e1gina de documenta\u00e7\u00e3o<\/a> :<\/span><\/p>\n<blockquote>\n<p> <span style=\"color: #000000;\">\u201cCom esse backend, o resultado dos comandos de rastreamento \u00e9 exibido <em>embutido<\/em> em frontends como o notebook Jupyter, diretamente abaixo da c\u00e9lula de c\u00f3digo que o produziu. As parcelas resultantes tamb\u00e9m ser\u00e3o armazenadas no documento do caderno.<\/span><\/p>\n<\/blockquote>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como usar esse c\u00f3digo na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo: como usar% matplotlibe online<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que estejamos tentando usar o seguinte c\u00f3digo para criar um gr\u00e1fico de linhas Matplotlib em um notebook Jupyter:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><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 x and y\n<\/span>x = [1, 6, 10]\ny = [5, 13, 27]\n\n<span style=\"color: #008080;\">#attempt to create line plot of x and y\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> (x, y)\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Esta \u00e9 a apar\u00eancia do resultado no notebook Jupyter:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-21656 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/en-ligne1.png\" alt=\"\" width=\"611\" height=\"207\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">O c\u00f3digo \u00e9 executado sem erros, mas nenhum gr\u00e1fico de linha \u00e9 exibido alinhado com o c\u00f3digo.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para resolver este problema, podemos usar o comando <strong>inline% matplotlib<\/strong> antes de criar o gr\u00e1fico de linhas:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #800080;\">%<\/span> matplotlib inline<\/span>\n\nimport<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#define x and y\n<\/span>x = [1, 6, 10]\ny = [5, 13, 27]\n\n<span style=\"color: #008080;\">#create scatter plot of x and y\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> (x, y)<\/span><\/span><\/strong>\n<\/pre>\n<p> <span style=\"color: #000000;\">Esta \u00e9 a apar\u00eancia do resultado no notebook Jupyter:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-21657 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/en-ligne2.png\" alt=\"\" width=\"656\" height=\"535\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Observe que o c\u00f3digo \u00e9 executado novamente sem erros e o gr\u00e1fico \u00e9 exibido embutido no Bloco de Notas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Observe que, uma vez que usarmos <strong>%matplotlib inline<\/strong> , quaisquer gr\u00e1ficos Matplotlib que criarmos em futuras c\u00e9lulas do notebook tamb\u00e9m ser\u00e3o exibidos e armazenados no notebook.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras opera\u00e7\u00f5es comuns em Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/erro-de-chave-do-pandas\/\" target=\"_blank\" rel=\"noopener\">Como corrigir KeyError em Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/valueerror-nao-pode-converter-float-nan-em-inteiro\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: ValueError: n\u00e3o \u00e9 poss\u00edvel converter float NaN em int<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/os-operandos-nao-puderam-ser-transmitidos-com-os-formularios\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: ValueError: os operandos n\u00e3o puderam ser transmitidos com formas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar o c\u00f3digo a seguir para exibir e armazenar gr\u00e1ficos Matplotlib em um notebook Python Jupyter: % matplotlib inline Veja como esse c\u00f3digo \u00e9 descrito na p\u00e1gina de documenta\u00e7\u00e3o : \u201cCom esse backend, o resultado dos comandos de rastreamento \u00e9 exibido embutido em frontends como o notebook Jupyter, diretamente abaixo da c\u00e9lula de [&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-2405","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.\" \/>\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\/pt\/matplotlib-on-line\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T10:17:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/en-ligne1.png\" \/>\n<meta name=\"author\" content=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/\",\"url\":\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/\",\"name\":\"Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-22T10:17:48+00:00\",\"dateModified\":\"2023-07-22T10:17:48+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/matplotlib-on-line\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como usar \u201c%matplotlib online\u201d (com exemplos)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia","description":"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.","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\/pt\/matplotlib-on-line\/","og_locale":"pt_PT","og_type":"article","og_title":"Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia","og_description":"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/","og_site_name":"Statorials","article_published_time":"2023-07-22T10:17:48+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/en-ligne1.png"}],"author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/","url":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/","name":"Como usar &quot;%matplotlib inline&quot; (com exemplos) - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-22T10:17:48+00:00","dateModified":"2023-07-22T10:17:48+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como usar a fun\u00e7\u00e3o \u201c%matplotlib inline\u201d em notebooks Python Jupyter, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/matplotlib-on-line\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/matplotlib-on-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como usar \u201c%matplotlib online\u201d (com exemplos)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=2405"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2405\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}