A graphics library that can be used to form publication quality figures.
For a comprehensive set of examples, refer to this material:
http://matplotlib.org/gallery.html
In [3]:
import matplotlib.pyplot as plt
import numpy as np
In [4]:
%matplotlib inline
The matplotlib API is both rich and deep, a good way to learn is to work through examples of the plots in the gallery.
In [5]:
data = np.random.randint(0, 10, (25))
In [6]:
figure, axis = plt.subplots(figsize=(8, 5))
axis.plot(data);
axis.grid()
We can change the line properties, color and axis properties.
In [7]:
figure, axis = plt.subplots(figsize=(8, 5))
axis.plot(data, color='r', marker='o', linestyle='--')
axis.grid()
axis.set_xlabel("Random variable")
axis.set_ylabel("Rangom value")
axis.set_title("Random figure")
axis.set_ylim(-1, data.max() + 1.)
Out[7]:
Q. Go to the matplotlib gallery and paste in an example.
In [8]:
"""
Demo of scatter plot on a polar axis.
Size increases radially in this example and color increases with angle (just to
verify the symbols are being scattered correctly).
"""
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, polar=True)
c = plt.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
c.set_alpha(0.75)
plt.show()
In [ ]: