{"id":2154,"date":"2023-03-21T16:23:32","date_gmt":"2023-03-21T16:23:32","guid":{"rendered":"https:\/\/ml4data.com\/?p=2154"},"modified":"2023-03-21T16:40:39","modified_gmt":"2023-03-21T16:40:39","slug":"motion-chart-with-plotly","status":"publish","type":"post","link":"https:\/\/ml4data.com\/index.php\/2023\/03\/21\/motion-chart-with-plotly\/","title":{"rendered":"Motion Chart with Plotly"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Motion Chart with Plotly<\/h2>\n\n\n\n<p>This is a concise script for creating a motion chart using Python and Plotly Express. <\/p>\n\n\n\n<p>The script loads the &#8216;gapminder&#8217; dataset, which contains information about the GDP per capita, life expectancy, population, and continent for various countries around the world. The script then creates a bubble chart using the data, with GDP per capita on the x-axis, life expectancy on the y-axis, and population represented by the size of the bubbles. <\/p>\n\n\n\n<p>The bubbles are also colored by continent, and the chart includes an animation feature that shows how these metrics change over time. <\/p>\n\n\n\n<p>The script also customizes the chart layout, adding a title and axis labels. Finally, the chart is displayed using the &#8216;show&#8217; method.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; first-line: 3; title: ; notranslate\" title=\"\">\nimport plotly.express as px\ndf = px.data.gapminder() # load the gapminder data\n\n# create a bubble chart using plotly express\nfig = px.scatter(df, x=&quot;gdpPercap&quot;, y=&quot;lifeExp&quot;, size=&quot;pop&quot;, color=&quot;continent&quot;, log_x=True,\n                  animation_frame=&quot;year&quot;, range_y=&#91;20, 90], hover_name=&quot;country&quot;, size_max=60)\n\n# customize the chart layout\nfig.update_layout(title='GDP vs Life Expectancy (Motion Chart)', xaxis_title='GDP per capita',\n                  yaxis_title='Life Expectancy', legend_title='Continent', height=600)\nfig.show()\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"468\" src=\"https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-1024x468.png\" alt=\"\" class=\"wp-image-2159\" srcset=\"https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-1024x468.png 1024w, https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-300x137.png 300w, https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-768x351.png 768w, https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-1536x702.png 1536w, https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-2048x936.png 2048w, https:\/\/ml4data.com\/wp-content\/uploads\/2023\/03\/motion_chart-600x274.png 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Motion Chart with Plotly This is a concise script for creating a motion chart using Python and Plotly Express. The script loads the &#8216;gapminder&#8217; dataset, which contains information about the GDP per capita, life expectancy, population, and continent for various countries around the world. The script then creates a bubble chart using the data, with [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"two_page_speed":[]},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/posts\/2154"}],"collection":[{"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/comments?post=2154"}],"version-history":[{"count":4,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/posts\/2154\/revisions"}],"predecessor-version":[{"id":2160,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/posts\/2154\/revisions\/2160"}],"wp:attachment":[{"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/media?parent=2154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/categories?post=2154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ml4data.com\/index.php\/wp-json\/wp\/v2\/tags?post=2154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}