First page Back Continue Last page Overview Graphics

Working with Objects

If the applications get more complex, it will be crucial to create and use figure instance for example.

Creating a plot in an object oriented way:

import numpy as np

import matplotlib.pyplot as plt

fig = plt.figure()

X = np.arange(0,10)

Y = np.random.randint(1,20, size=10)

left, bottom, width, height = 0.1, 0.1, 0.8, 0.8

axes = fig.add_axes([left, bottom, width, height])

axes.plot(X, Y, 'g')

plt.show(fig)