Array represents Pic

need to install a third party library, pip install pillow, read pic --> convert by PIL --> save as another pic

Matpotlib

Partition and location

If I need more than one figure, how can I make it? Just like the figure below.

plt.subplot code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pip install matpotlib # first use needing to intall the third party library
import matplotlib.pyplot as plt
import numpy as np

a =np.arange(0.0,5.0,0.02)

plt.subplot(2,1,1) #partition and location
plt.plot([1,6,2],[3,4,7])
plt.ylabel("Grade")

plt.subplot(2,1,2)
plt.plot(a,np.cos(2*np.pi*a),"r,-")
plt.ylabel("Grade")

plt.show()

more complex grid, use plt.subplot2grid(), just like the code below

1
plt.subplot2grid((3,3),(0,0),colspan=3/rowspan=2)

Or use matplotlib.gridspec, making a grid shown as in the figure below

matplotlib.gridspec code
1
2
3
4
5
6
7
8
9
10
11
12
13
import matplotlib.gridspec as gsp

gs = gsp.GridSpec(3, 3)

ax1 = plt.subplot(gs[0, :])

ax2 = plt.subplot(gs[1, :-1])

ax2 = plt.subplot(gs[1:, 2])
ax2 = plt.subplot(gs[2, 0])
ax2 = plt.subplot(gs[2, 1]) # or using 'ax2 = plt.subplot(gs[-1, 1])'

plt.show()
0 1 2 or -1
1
2 or -1

And what is the meaning of x, y, z in the plt.subplot(gs[x, y:z]) ?
Especially,‘,’ is a divider.
The left part represents the index of row, and the right part represent the index of column. Swaping the left and right part can lead to a block rotate 90 degrees.

Supporte Chinese

中文字体
fontproperties中文字体
Simhei黑体

评论