{"id":3655,"date":"2017-07-22T05:32:10","date_gmt":"2017-07-22T05:32:10","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=3655"},"modified":"2021-03-20T14:24:19","modified_gmt":"2021-03-20T14:24:19","slug":"how-to-plot-two-graphs-on-the-same-figure","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-plot-two-graphs-on-the-same-figure\/","title":{"rendered":"How to plot two graphs on the same figure"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>In this tutorial, we will learn the steps involved in adding two graphs to the same figure. To achieve this we need to use subplots in the Octave script code. Subplots allow us to plot one or more plots in a single figure. In this example, let&#8217;s plot two sample functions sin(x) and cos(x) using GNU Octave.<\/p>\n<h3>Octave Code<\/h3>\n<pre>% Subplots Example\r\n        % www.TestingDocs.com\r\n        % x points vector for plot\r\n        x=linspace(0,5*pi,50);\r\n        figure;\r\n        hold on;\r\n        subplot(2,1,1);\r\n        y1=cos(x);\r\n        plot(x,y1);\r\n        title('cos(x) - www.TestingDocs.com');\r\n        xlabel('x-axis');\r\n        ylabel('y-axis');\r\n\r\n        subplot(2,1,2);\r\n        y2= sin(x);\r\n        plot(x,y2);\r\n        title('sin(x) - www.TestingDocs.com ');\r\n        xlabel('x-axis');\r\n        ylabel('y-axis');<\/pre>\n<pre><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3657\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code.png\" alt=\"Octave Subplot Script Code\" width=\"1920\" height=\"1080\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code-300x169.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code-1024x576.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code-768x432.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Octave-Subplot-Script-Code-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3656\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave.png\" alt=\"Two Subplots Octave\" width=\"1920\" height=\"1080\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave-300x169.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave-1024x576.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave-768x432.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Subplots-Octave-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Octave Tutorial on this website can be found at:<br \/>\n<a href=\"https:\/\/www.testingdocs.com\/octave-tutorial\/\">https:\/\/www.testingdocs.com\/octave-tutorial\/<\/a><\/p>\n<p>More information on Octave can be found on the official website:<br \/>\n<a href=\"https:\/\/www.gnu.org\/software\/octave\/index\" rel=\"noopener\">https:\/\/www.gnu.org\/software\/octave\/index<\/a><\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-3655\" data-postid=\"3655\" class=\"themify_builder_content themify_builder_content-3655 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this tutorial, we will learn the steps involved in adding two graphs to the same figure. To achieve this we need to use subplots in the Octave script code. Subplots allow us to plot one or more plots in a single figure. In this example, let&#8217;s plot two sample functions sin(x) and cos(x) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-3655","post","type-post","status-publish","format-standard","hentry","category-octave","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=3655"}],"version-history":[{"count":6,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3655\/revisions"}],"predecessor-version":[{"id":19594,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3655\/revisions\/19594"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=3655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=3655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=3655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}