<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>subplot Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/subplot/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/subplot/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Mon, 27 Oct 2025 09:41:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Introduction to matplotlib &#8211; Part 2</title>
		<link>https://creatronix.de/introduction-to-matplotlib-part-2/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 18 Dec 2018 09:12:40 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[linspace]]></category>
		<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[subplot]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=2182</guid>

					<description><![CDATA[<p>When you finished reading part 1 of the introduction you might have wondered how to draw more than one line or curve into on plot. I will show you now. To make it a bit more interesting we generate two functions: sine and cosine. We generate our x-values with numpy&#8217;s linspace function import numpy as&#8230;</p>
<p>The post <a href="https://creatronix.de/introduction-to-matplotlib-part-2/">Introduction to matplotlib &#8211; Part 2</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When you finished reading <a href="https://creatronix.de/introduction-to-matplotlib/">part 1</a> of the introduction you might have wondered how to draw more than one line or curve into on plot. I will show you now.</p>
<p>To make it a bit more interesting we generate two functions: sine and cosine. We generate our x-values with numpy&#8217;s <a href="https://creatronix.de/numpy-linspace-function/">linspace function</a></p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>import numpy as np 
import matplotlib.pyplot as plt 

x = np.linspace(0, 2*np.pi) 
sin = np.sin(x) 
cos = np.cos(x) 
plt.plot(x, sin, color='b') 
plt.plot(x, cos, color='r') 
plt.show()</code></pre>
</div>
<p>You can plot two or more curves by repeatedly calling the plot method.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2184" src="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_21.png" alt="" width="640" height="480" srcset="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_21.png 640w, https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_21-300x225.png 300w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>That&#8217;s fine as long as the individual plots share the same axis-description and values.</p>
<h2>Subplots</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>fig = plt.figure() 
p1 = fig.add_subplot(2, 1, 1) 
p2 = fig.add_subplot(2, 1, 2) 
p1.plot(x, sin, c='b') 
p2.plot(x, cos, c='r'</code></pre>
</div>
<p>The add_subplot method allows us to put many plots into one &#8220;parent&#8221; plot aka figure. The arguments are (number_of_rows, number_of_columns, place in the matrix) So in this example we have 2 rows in 1 column, sine is in first, cosine in second position:</p>
<p><img decoding="async" class="alignnone size-full wp-image-2186" src="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_22.png" alt="" width="640" height="480" srcset="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_22.png 640w, https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_22-300x225.png 300w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>when you have a 2 by 2 matrix it is counted from columns to row</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>fig = plt.figure() 
p1 = fig.add_subplot(221) 
p2 = fig.add_subplot(222) 
p3 = fig.add_subplot(223) 
p4 = fig.add_subplot(224) 
p1.plot(x, sin, c='b') 
p2.plot(x, cos, c='r') 
p3.plot(x, -sin, c='g') 
p4.plot(x, -cos, c='y')</code></pre>
</div>
<p><img decoding="async" class="alignnone size-full wp-image-2199" src="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_23.png" alt="" width="640" height="480" srcset="https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_23.png 640w, https://creatronix.de/wp-content/uploads/2018/10/pyplot_plot_23-300x225.png 300w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>The code is available as a <a href="https://github.com/jboegeholz/introduction_to_matplotlib/blob/master/02_subplots.ipynb">Jupyter Notebook on my github </a></p>
<p>More about matplotlib in <a href="https://creatronix.de/introduction-to-matplotlib-part-3/">Part 3</a></p>
<p>The post <a href="https://creatronix.de/introduction-to-matplotlib-part-2/">Introduction to matplotlib &#8211; Part 2</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
