forked from Jayhello/python_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_many.py
More file actions
129 lines (98 loc) · 3.05 KB
/
Copy pathplot_many.py
File metadata and controls
129 lines (98 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# _*_ coding:utf-8 _*_
"""
This file is about subplot
mainly cited from `http://matplotlib.org/examples/pylab_examples/subplots_demo.html`
"""
import numpy as np
import matplotlib.pyplot as plt
def plot_mul():
left, width = 0.1, 0.8
ax1 = plt.axes([left, 0.5, width, 0.45])
ax2 = plt.axes([left, 0.3, width, 0.19])
ax3 = plt.axes([left, 0.2, width, 0.09], sharex=ax2)
ax4 = plt.axes([left, 0.1, width, 0.09], sharex=ax2)
# ticks at the top of the top plot
ax1.xaxis.tick_top()
# remove ticks for ax2 and ax3
ax2.xaxis.set_visible(False)
ax3.xaxis.set_visible(False)
# only put ticks on the bottom of ax4
ax4.xaxis.tick_bottom()
plt.show()
def subplot_demo1():
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
# Just a figure and one subplot
f, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')
plt.show()
def subplot_demo2():
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
f, ax_arr = plt.subplots(2, sharex=True)
ax_arr[0].plot(x, y)
ax_arr[0].set_title('sharing x axis')
ax_arr[1].scatter(x, y)
plt.show()
def subplot_demo3():
# Two subplots, unpack the axes array immediately
x = np.linspace(0, 2 * np.pi, 300)
y = np.sin(x ** 2)
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing Y axis')
ax2.scatter(x, y)
plt.show()
def subplots_demo4():
x = np.linspace(0, 2 * np.pi, 300)
y = np.sin(x ** 2)
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
ax1.plot(x, y)
ax1.set_title('sharing x axis')
ax2.scatter(x, y)
x1 = [1, 2, 3, 4, 5, 6, 7]
y1 = [2.6, 3.6, 8.3, 56, 12.7, 8.9, 5.3]
ax3.scatter(x1, y1)
plt.show()
def subplots_demo5():
x = np.linspace(0, 2 * np.pi, 300)
y = np.sin(x ** 2)
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
ax1.plot(x, y)
ax1.set_title('Sharing x per column, y per row')
ax2.scatter(x, y)
ax2.set_title('ax2')
ax3.plot(x, 2 * y ** 2 + 1, color='r')
ax3.set_title('ax3')
ax4.plot(x, 2 * y ** 2 + 1, color='b')
ax4.set_title('ax4')
plt.show()
pass
def subplots_demo6():
x = np.linspace(0, 2 * np.pi, 300)
y = np.sin(x ** 2)
f, ax_arr = plt.subplots(2, 2)
ax_arr[0, 0].plot(x, y)
ax_arr[0, 0].set_title('axis 0, 0')
ax_arr[0, 1].scatter(x, y)
ax_arr[0, 1].set_title('axis 0, 1')
ax_arr[1, 0].plot(x, y ** 2)
ax_arr[1, 0].set_title('axis 1, 0')
ax_arr[1, 1].scatter(x, y ** 2)
ax_arr[1, 1].set_title('axis 1, 1')
# for row 0, every element x axis hidden
plt.setp([ax.get_xticklabels() for ax in ax_arr[0, :]], visible=False)
# for column 1, every element y axis hidden
plt.setp([ax.get_yticklabels() for ax in ax_arr[:, 1]], visible=False)
plt.show()
if __name__ == '__main__':
# plot_mul()
# subplot_demo1()
# subplot_demo2()
# subplot_demo3()
# subplots_demo4()
# subplots_demo5()
subplots_demo6()
pass