{"id":2108,"date":"2023-07-23T15:56:13","date_gmt":"2023-07-23T15:56:13","guid":{"rendered":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/"},"modified":"2023-07-23T15:56:13","modified_gmt":"2023-07-23T15:56:13","slug":"cor-aleatoria-matplotlib","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/","title":{"rendered":"Como gerar cores aleat\u00f3rias em gr\u00e1ficos matplotlib"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar a seguinte sintaxe b\u00e1sica para gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>1. Gere cores aleat\u00f3rias para gr\u00e1fico de linha<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>col = <span style=\"color: #3366ff;\">(<\/span> <span style=\"color: #3366ff;\">np.random.random<\/span> (), <span style=\"color: #3366ff;\">np.random.random<\/span> (), <span style=\"color: #3366ff;\">np.random.random<\/span> <span style=\"color: #3366ff;\">(<\/span> <span style=\"color: #3366ff;\">)<\/span> )\n\nplt. <span style=\"color: #3366ff;\">plot<\/span> (x, y, c=col)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>2. Gere cores aleat\u00f3rias para a nuvem de pontos<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>plt. <span style=\"color: #3366ff;\">scatter<\/span> (x, y, c=np. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">rand<\/span> (len(x), <span style=\"color: #008000;\">3<\/span> ))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar essa sintaxe na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: Gere uma cor aleat\u00f3ria para o gr\u00e1fico de linha<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como gerar uma cor aleat\u00f3ria para uma \u00fanica linha em um gr\u00e1fico linear:<\/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;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#define data\n<\/span>x = [1, 2, 3, 4, 5]\ny = [7, 12, 15, 19, 25]\n\n<span style=\"color: #008080;\">#define random color\n<\/span>col = <span style=\"color: #3366ff;\">(<\/span> <span style=\"color: #3366ff;\">np.random.random<\/span> (), <span style=\"color: #3366ff;\">np.random.random<\/span> (), <span style=\"color: #3366ff;\">np.random.random<\/span> <span style=\"color: #3366ff;\">(<\/span> <span style=\"color: #3366ff;\">)<\/span> )\n\n<span style=\"color: #008080;\">#create line plot with random color\n<\/span>plt. <span style=\"color: #3366ff;\">plot<\/span> (x, y, c=col) \n<\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19606 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire1.png\" alt=\"\" width=\"546\" height=\"357\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Se executarmos exatamente o mesmo trecho de c\u00f3digo novamente, um caminho de linha com uma cor aleat\u00f3ria diferente ser\u00e1 criado:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19607 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire2-1.png\" alt=\"\" width=\"544\" height=\"359\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <strong>Exemplo 2: Gere cores aleat\u00f3rias para uma nuvem de pontos<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como criar um gr\u00e1fico de dispers\u00e3o com cores aleat\u00f3rias para cada ponto do gr\u00e1fico:<\/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<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#define data<\/span>\nx = [1, 2, 3, 4, 5]\ny = [7, 12, 15, 19, 25]\n\n<span style=\"color: #008080;\">#create scatterplot with random colors for each point\n<\/span>plt. <span style=\"color: #3366ff;\">scatter<\/span> (x, y, c=np. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">rand<\/span> (len(x),3))\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19608 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire3.png\" alt=\"\" width=\"532\" height=\"352\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Se executarmos exatamente o mesmo c\u00f3digo novamente, um gr\u00e1fico de dispers\u00e3o com novas cores aleat\u00f3rias para cada ponto ser\u00e1 criado:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19609 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire4.png\" alt=\"\" width=\"537\" height=\"359\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota:<\/strong> Nos bastidores, este c\u00f3digo simplesmente usa NumPy para gerar cores aleat\u00f3rias (R, G, B).<\/span><\/p>\n<p> <span style=\"color: #000000;\">Consulte a <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/random\/generated\/numpy.random.random.html\" target=\"_blank\" rel=\"noopener\">documenta\u00e7\u00e3o online<\/a> para obter uma explica\u00e7\u00e3o completa da fun\u00e7\u00e3o NumPy <strong>random()<\/strong> .<\/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 executar outras fun\u00e7\u00f5es de plotagem comuns no Matplotlib:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/cor-de-fundo-do-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Como alterar a cor de fundo no Matplotlib<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/grafico-de-dispersao-de-cor-por-valor-do-matplotlib\/\" target=\"_blank\" rel=\"noopener\">Como colorir um gr\u00e1fico de dispers\u00e3o por valor no Matplotlib<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar a seguinte sintaxe b\u00e1sica para gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib: 1. Gere cores aleat\u00f3rias para gr\u00e1fico de linha col = ( np.random.random (), np.random.random (), np.random.random ( ) ) plt. plot (x, y, c=col) 2. Gere cores aleat\u00f3rias para a nuvem de pontos plt. scatter (x, y, c=np. random . rand [&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-2108","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 gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.\" \/>\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\/cor-aleatoria-matplotlib\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T15:56:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire1.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\/cor-aleatoria-matplotlib\/\",\"url\":\"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/\",\"name\":\"Como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-23T15:56:13+00:00\",\"dateModified\":\"2023-07-23T15:56:13+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como gerar cores aleat\u00f3rias em gr\u00e1ficos matplotlib\"}]},{\"@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 gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia","description":"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.","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\/cor-aleatoria-matplotlib\/","og_locale":"pt_PT","og_type":"article","og_title":"Como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia","og_description":"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/","og_site_name":"Statorials","article_published_time":"2023-07-23T15:56:13+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/aleatoire1.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\/cor-aleatoria-matplotlib\/","url":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/","name":"Como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-23T15:56:13+00:00","dateModified":"2023-07-23T15:56:13+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como gerar cores aleat\u00f3rias em gr\u00e1ficos Matplotlib, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/cor-aleatoria-matplotlib\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como gerar cores aleat\u00f3rias em gr\u00e1ficos matplotlib"}]},{"@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\/2108","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=2108"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2108\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}