4. Advanced plotting

4.1. Motivation, prerequisites, plan

Motivation

Sometimes we want to do more advanced plotting […]

Prerequisites

  • The 10-hour “serious programming” course.
  • The “Data files and first plots” mini-course in Section 2.
  • The “Intermediate plotting” mini-course in Section 3.

Plan

We will:

[…]

4.2. Logarithmic scales

log y

log x and log y

4.3. Animation in matplotlib

simple-animated-plot.py

Listing 4.3.1 simple-animated-plot.py – …
#! /usr/bin/env python3

## example taken from https://stackoverflow.com/a/42738014

import matplotlib.pyplot as plt
import numpy as np

plt.ion()
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y)
plt.xlim(0,10)
plt.ylim(0,10)

plt.draw()
for i in range(1000):
    x.append(np.random.rand(1)*10)
    y.append(np.random.rand(1)*10)
    sc.set_offsets(np.c_[x,y])
    fig.canvas.draw_idle()
    plt.pause(0.1)

plt.waitforbuttonpress()