<jupyter_start><jupyter_text>matplotlib[matplotlib](http://matplotlib.org) is the most used to plot. It is the *reference*. Every plotting library works the same way: * We define axis (they boundaries can be adjusted based on the data)* We add curves, points, surfaces (A).* We add legendes (B).* We convert the plot into an image.Step (A) and (B) can be repeated in any order. Curves and legends superimposed.[documentation](http://matplotlib.org/) [source](https://github.com/matplotlib/matplotlib) [installation](http://matplotlib.org/users/installing.html) [tutorial](http://matplotlib.org/users/pyplot_tutorial.html) [gallery](http://matplotlib.org/gallery.html)<jupyter_code>%matplotlib inline
from jyquickhelper import add_notebook_menu
add_notebook_menu()<jupyter_output><empty_output><jupyter_text>SetupSome parts of *matplotlib* are written in C and needs to be compiled. Thus the instruction ``pip install matplotlib`` usually fails on Windows unless [Visual Studio 2015 Community Edition](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx) is installed. I recommend to use a precompiled version through ``conda install matplotlib`` or  [Unofficial Windows Binaries for Python Extension Packages](http://www.lfd.uci.edu/~gohlke/pythonlibs/) sous Windows.<jupyter_code>import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>First example<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2 * np.random.rand(N)
colors = theta

ax = plt.subplot(111, projection='polar')
c = plt.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
c.set_alpha(0.75)<jupyter_output><empty_output><jupyter_text>AnimationTo make it work:* Install [ffmpeg](https://ffmpeg.org/) on Windows or [avconv](https://libav.org/avconv.html) on Linux* On Windows, open file ``matplotlibrc`` and update parameter ``animation.ffmpeg_path``. On Linux, the same must be done for *avconv*.<jupyter_code>import matplotlib
matplotlib.matplotlib_fname()
import os
matplotlib.rcParams['animation.ffmpeg_path'].replace(os.environ.get("USERPROFILE", "~"), "<user>")
import matplotlib.animation
matplotlib.animation.writers.list()<jupyter_output><empty_output><jupyter_text>Let's take an example from matplotlib documentation [bayes_update](http://matplotlib.org/1.4.1/examples/animation/bayes_update.html).<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def data_gen():
    t = data_gen.t
    cnt = 0
    while cnt < 1000:
        cnt+=1
        t += 0.05
        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
data_gen.t = 0

fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 5)
ax.grid()
xdata, ydata = [], []
def run(data):
    # update the data
    t,y = data
    xdata.append(t)
    ydata.append(y)
    xmin, xmax = ax.get_xlim()

    if t >= xmax:
        ax.set_xlim(xmin, 2*xmax)
        ax.figure.canvas.draw()
    line.set_data(xdata, ydata)

    return line,

anim = animation.FuncAnimation(fig, run, data_gen, blit=True, interval=10, repeat=False)

# saves the video
from matplotlib.animation import writers
Writer = writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
anim.save('lines2.mp4', writer=writer)
import os
[_ for _ in os.listdir(".") if "mp4" in _]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13544083526682135, 'fraction_numerical': 0.015661252900232018, 'mean_word_length': 5.093639575971731, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '363246', 'license': 'MIT', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1197, 'n_words': 297, 'path': '_doc/notebooks/2016/pydata/im_matplotlib.ipynb', 'repo_name': 'sdpython/jupytalk', 'size': '3448'}