1import pandas as pd
2import matplotlib.pyplot as plt
3
4d = {'series a' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
5 'series b' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
6df = pd.DataFrame(d)
7
8title_string = "This is the title"
9subtitle_string = "This is the subtitle"
10
11plt.figure()
12df.plot(kind='bar')
13plt.suptitle(title_string, y=1.05, fontsize=18)
14plt.title(subtitle_string, fontsize=10)
1# First create some toy data:
2x = np.linspace(0, 2*np.pi, 400)
3y = np.sin(x**2)
4
5# Creates just a figure and only one subplot
6fig, ax = plt.subplots()
7ax.plot(x, y)
8ax.set_title('Simple plot')
9
10# Creates two subplots and unpacks the output array immediately
11f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
12ax1.plot(x, y)
13ax1.set_title('Sharing Y axis')
14ax2.scatter(x, y)
15
16# Creates four polar axes, and accesses them through the returned array
17fig, axes = plt.subplots(2, 2, subplot_kw=dict(polar=True))
18axes[0, 0].plot(x, y)
19axes[1, 1].scatter(x, y)
20
21# Share a X axis with each column of subplots
22plt.subplots(2, 2, sharex='col')
23
24# Share a Y axis with each row of subplots
25plt.subplots(2, 2, sharey='row')
26
27# Share both X and Y axes with all subplots
28plt.subplots(2, 2, sharex='all', sharey='all')
29
30# Note that this is the same as
31plt.subplots(2, 2, sharex=True, sharey=True)
32
33# Creates figure number 10 with a single subplot
34# and clears it if it already exists.
35fig, ax=plt.subplots(num=10, clear=True)
1import matplotlib.pyplot as plt
2import numpy as np
3
4fig=plt.figure()
5data=np.arange(900).reshape((30,30))
6for i in range(1,5):
7 ax=fig.add_subplot(2,2,i)
8 ax.imshow(data)
9
10fig.suptitle('Main title') # or plt.suptitle('Main title')
11plt.show()
12