Chapter 4, example 4

In this example, we show a few plotting customization options.

We can easily specify the color and line style of each plot.


In [1]:
%pylab inline


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [2]:
x = linspace(-10, 10, 1000)
plot(x, sin(x), '-r')
plot(x, cos(x), '--g')


Out[2]:
[<matplotlib.lines.Line2D at 0x58319d0>]

Here are a few other customization options:


In [3]:
plot(x, sin(x), '-r', label='sine')
plot(x, cos(x), '--g', label='cosine')
xticks([-10, 0, 10])
yticks([-1, 0, 1])
ylim(-2, 2)
legend()
grid()


We can plot Cartesian and polar plots side by side.


In [4]:
x = linspace(0, 2 * pi, 1000)
y = 1 + 2 * cos(5 * x)
subplot(121)
plot(x, y)
subplot(122, polar=True)
polar(x, y)


Out[4]:
[<matplotlib.lines.Line2D at 0x5b6f2d0>]