{"id":37291,"date":"2024-11-01T09:56:25","date_gmt":"2024-11-01T09:56:25","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37291"},"modified":"2024-11-01T11:51:24","modified_gmt":"2024-11-01T11:51:24","slug":"automatic-trading-development-in-python-figure-and-subplots","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37291\/","title":{"rendered":"Automatic Trading Development in Python, Figure and Subplots"},"content":{"rendered":"<p><body><\/p>\n<p>Python is a very useful language for data analysis and implementing automated trading systems. In particular, data visualization using the Matplotlib library is a great help in understanding market movements and making trading decisions. This article will explain in detail how to implement effective data visualization through the concepts of Figure and Subplots in Matplotlib. We will practice with a simple stock price data example.<\/p>\n<h2>1. Introduction to Matplotlib Library<\/h2>\n<p>Matplotlib is one of the most widely used data visualization libraries in Python, allowing you to create various types of graphs. In particular, using Figure and Subplots makes it easy to compare multiple graphs by placing them on one screen.<\/p>\n<h2>2. Understanding the Concept of Figure<\/h2>\n<p>A Figure is the top-level object in Matplotlib that can contain one or more subplots. The Figure is used to set the size and elements of the overall graph. To draw a graph using Matplotlib, you must first create a Figure.<\/p>\n<h2>3. Understanding the Concept of Subplots<\/h2>\n<p>Subplots are a way to place multiple individual graphs within a single Figure. Utilizing the subplot feature is very useful for comparing multiple data at a glance. Below is a basic method for setting up Subplots.<\/p>\n<h3>3.1 How to Create Subplots<\/h3>\n<p>To create a subplot, you can use the <code>plt.subplots()<\/code> function to specify the desired number of rows and columns. Here&#8217;s a basic usage example:<\/p>\n<pre><code>python\nimport matplotlib.pyplot as plt\n\n# Create Subplots\nfig, axs = plt.subplots(2, 2)  # Create a 2x2 shape subplot\n\n# Add sample data to each subplot\naxs[0, 0].plot([1, 2, 3], [1, 4, 9])\naxs[0, 0].set_title('First Graph')\n\naxs[0, 1].plot([1, 2, 3], [1, 2, 1])\naxs[0, 1].set_title('Second Graph')\n\naxs[1, 0].plot([1, 2, 3], [1, 0, 1])\naxs[1, 0].set_title('Third Graph')\n\naxs[1, 1].plot([1, 2, 3], [2, 2, 2])\naxs[1, 1].set_title('Fourth Graph')\n\n# Adjust layout\nplt.tight_layout()\nplt.show()\n<\/code><\/pre>\n<h2>4. Example of Building a Stock Automated Trading System<\/h2>\n<p>In this section, we will visualize a simple stock data serving as the basis for an automated trading system. We will retrieve data via the Yahoo Finance API and visualize the price trend using Matplotlib.<\/p>\n<h3>4.1 Installing Required Libraries and Data Collection<\/h3>\n<p>We will use the <code>yfinance<\/code> library to collect data. Please install the necessary libraries in your Python environment as follows:<\/p>\n<pre><code>bash\npip install yfinance matplotlib\n<\/code><\/pre>\n<h3>4.2 Example Code for Data Collection<\/h3>\n<p>Below is an example code that collects and visualizes the stock data of Apple Inc.<\/p>\n<pre><code>python\nimport yfinance as yf\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\n# Retrieve data\nstock = yf.Ticker(\"AAPL\")\ndata = stock.history(period=\"1y\")  # Get data for one year\n\n# Visualize data\nfig, axs = plt.subplots(2, 1, figsize=(10, 10))  # 2x1 subplot\n\n# Closing price graph\ndata['Close'].plot(ax=axs[0])\naxs[0].set_title('AAPL Closing Price')\naxs[0].set_ylabel('Price')\n\n# Volume graph\ndata['Volume'].plot(ax=axs[1])\naxs[1].set_title('AAPL Volume')\naxs[1].set_ylabel('Volume')\n\nplt.tight_layout()\nplt.show()\n<\/code><\/pre>\n<h2>5. Adding Technical Indicator<\/h2>\n<p>Now, let&#8217;s add a simple technical indicator, the Moving Average, to make the graph even more useful. The moving average helps in understanding the price trend by calculating the average price.<\/p>\n<h3>5.1 Example Code for Adding Moving Average<\/h3>\n<p>The code below calculates the 20-day and 50-day moving averages for the stock price data and adds them to the graph.<\/p>\n<pre><code>python\n# Calculate moving average\ndata['MA20'] = data['Close'].rolling(window=20).mean()\ndata['MA50'] = data['Close'].rolling(window=50).mean()\n\n# Visualization\nfig, axs = plt.subplots(2, 1, figsize=(10, 10))\n\n# Closing price and moving averages\naxs[0].plot(data['Close'], label='Closing Price', color='blue')\naxs[0].plot(data['MA20'], label='20-Day Moving Average', color='orange')\naxs[0].plot(data['MA50'], label='50-Day Moving Average', color='green')\naxs[0].set_title('AAPL Closing Price and Moving Averages')\naxs[0].set_ylabel('Price')\naxs[0].legend()\n\n# Volume graph\ndata['Volume'].plot(ax=axs[1])\naxs[1].set_title('AAPL Volume')\naxs[1].set_ylabel('Volume')\n\nplt.tight_layout()\nplt.show()\n<\/code><\/pre>\n<h2>6. Conclusion<\/h2>\n<p>In this article, we explained how to build the foundational visualizations necessary for an automated trading system using Python&#8217;s Matplotlib library. By understanding the concepts of Figure and Subplots, we were able to visualize multiple data simultaneously and enrich our analysis by adding a simple moving average. Integrating this visualization into actual automated trading algorithms can lead to better trading decisions.<\/p>\n<p>Additionally, by practicing with real market data and applying various technical indicators, one can further improve the automated trading system. We encourage you to continue learning about data visualization and algorithmic trading with Python.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is a very useful language for data analysis and implementing automated trading systems. In particular, data visualization using the Matplotlib library is a great help in understanding market movements and making trading decisions. This article will explain in detail how to implement effective data visualization through the concepts of Figure and Subplots in Matplotlib. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37291\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Automatic Trading Development in Python, Figure and Subplots&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[147],"tags":[],"class_list":["post-37291","post","type-post","status-publish","format-standard","hentry","category-python-auto-trading"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37291\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Python is a very useful language for data analysis and implementing automated trading systems. In particular, data visualization using the Matplotlib library is a great help in understanding market movements and making trading decisions. This article will explain in detail how to implement effective data visualization through the concepts of Figure and Subplots in Matplotlib. &hellip; \ub354 \ubcf4\uae30 &quot;Automatic Trading Development in Python, Figure and Subplots&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37291\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:56:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:51:24+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Automatic Trading Development in Python, Figure and Subplots\",\"datePublished\":\"2024-11-01T09:56:25+00:00\",\"dateModified\":\"2024-11-01T11:51:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/\"},\"wordCount\":479,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37291\/\",\"name\":\"Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:56:25+00:00\",\"dateModified\":\"2024-11-01T11:51:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37291\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37291\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatic Trading Development in Python, Figure and Subplots\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/37291\/","og_locale":"ko_KR","og_type":"article","og_title":"Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Python is a very useful language for data analysis and implementing automated trading systems. In particular, data visualization using the Matplotlib library is a great help in understanding market movements and making trading decisions. This article will explain in detail how to implement effective data visualization through the concepts of Figure and Subplots in Matplotlib. &hellip; \ub354 \ubcf4\uae30 \"Automatic Trading Development in Python, Figure and Subplots\"","og_url":"https:\/\/atmokpo.com\/w\/37291\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:56:25+00:00","article_modified_time":"2024-11-01T11:51:24+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37291\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37291\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Automatic Trading Development in Python, Figure and Subplots","datePublished":"2024-11-01T09:56:25+00:00","dateModified":"2024-11-01T11:51:24+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37291\/"},"wordCount":479,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37291\/","url":"https:\/\/atmokpo.com\/w\/37291\/","name":"Automatic Trading Development in Python, Figure and Subplots - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:56:25+00:00","dateModified":"2024-11-01T11:51:24+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37291\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37291\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37291\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Automatic Trading Development in Python, Figure and Subplots"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37291"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37291\/revisions"}],"predecessor-version":[{"id":37292,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37291\/revisions\/37292"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}