How modules know each other
<p>I can plot data from a CSV file with the following code:</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test0.csv',delimiter='; ', engine='python')
df.plot(x='Column1', y='Column3')
plt.show()
</code></pre>

<p>But I don't understand one thing. How <code>plt.show()</code> knows about <code>df</code>? I'll make more sense to me seeing, somewhere, an expression like:</p>

<pre><code>plt = something(df)
</code></pre>

<p>I have to mention I'm just learning Python.</p>

<p>From the pandas docs on <a href="https://github.com/pydata/pandas/blob/cebc70cc277462176edea73bb71eaad9f83e9f47/doc/source/visualization.rst#basic-plotting-plot" rel="nofollow">plotting</a>:</p>

<blockquote>
  <p>The <code>plot</code> method on Series and DataFrame is just a simple wrapper
  around :meth:<code>plt.plot() &lt;matplotlib.axes.Axes.plot&gt;</code></p>
</blockquote>

<p>So as is, the <code>df.plot</code> method is an highlevel call to <code>plt.plot</code> (using a <em>wrapper</em>), and thereafter, calling <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/pyplot.py#L240" rel="nofollow"><code>plt.show</code></a> will simply:</p>

<blockquote>
  <p>display all figures and block until the figures have been closed</p>
</blockquote>

<p>as it would with for all figures plotted with <code>plt.plot</code>.</p>

<hr>

<p>Therefore, you don't see <code>plt = something(df)</code> as you would expect, because <code>matpotlib.pyplot.plot</code> is being called <em>behind the scene</em> by <code>df.plot</code>.</p>

python python-2.7