Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
134 lines (103 loc) · 2.95 KB

File metadata and controls

134 lines (103 loc) · 2.95 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
130
131
132
133
134
# _*_ coding:utf-8 _*_
"""
This file is about `matplotlib`
Mainly cited from http://matplotlib.org/users/pyplot_tutorial.html
"""
import matplotlib.pyplot as plt
import numpy as np
import random
def basic_linear():
y_lst = [1, 2, 3, 4]
# y_lst = random.sample(range(80000), 500)
plt.plot(y_lst)
plt.ylabel('y axis value')
plt.show()
def plot_x1_y4():
"""
plot a line x = 1
:return:
"""
plt.plot([0, 0], [0, 4], color='red', linewidth=3.0)
plt.axis([-1, 1, -4, 4])
plt.show()
def basic_curve():
x = np.linspace(0, 2, 11)
print x
y = x ** 3 - 5 * x ** 2 + 6 * x + 1
print y
# plt.plot(x, y, 'r-')
# plt.plot(x, y)
lines = plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.setp(lines, color='r')
plt.show()
# plt.axis([0, 100, 0, 100])
def multi_curve():
t = np.arange(0., 5., 0.2)
print t
# plt.plot(t, t, 'r-', t, t**2, 'bs', t, t**3, 'g^')
# plt.show()
def f(t):
return np.exp(-t) * np.cos(2 * np.pi * t)
def multi_figure():
plt.figure(1) # the first figure
plt.subplot(211) # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212) # the second subplot in the first figure
plt.plot([4, 5, 6, 7, 11])
plt.figure(2) # a second figure
plt.plot([4, 5, 6]) # creates a subplot(111) by default
plt.figure(1) # figure 1 current; subplot(212) still current
plt.subplot(211) # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
plt.show()
def multi_figure_two():
t1 = np.arange(0., 5, 0.1)
t2 = np.arange(0., 5, 0.02)
plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2 * np.pi * t2), 'bo')
plt.show()
def histogram():
x_mul = [np.random.randn(n) for n in [1000, 1000, 1000]]
print x_mul
bin = 10
plt.hist(x_mul, bin)
plt.show()
def histogram_two():
x_mul = [random.sample(range(0, 100), n) for n in [60, 50, 70]]
print x_mul[0]
print x_mul[1]
print x_mul[2]
bin = 10
plt.hist(x_mul, bin)
plt.show()
def plot_2d():
x = [1, 2, 3, 4, 5, 6, 7]
y = [2.6, 3.6, 8.3, 56, 12.7, 8.9, 5.3]
plt.plot(x, y) # plot line
# plt.scatter(x, y) # plot scatter
plt.show()
def plot_orthogonal():
arr = np.array([[-0.85389096, -0.52045195], [0.52045195, -0.85389096]])
# arr = np.array([[1, -1], [1, 1]])
v1_x, v2_x = [arr[:, 0][0], 0], [arr[:, 1][0], 0]
v1_y, v2_y = [arr[:, 0][1], 0], [arr[:, 1][1], 0]
plt.plot(v1_x, v1_y)
plt.plot(v2_x, v2_y)
# plt.axis([-1, 1, -1, 1])
# set the below bound, or the line won't seem orthogonal
# plt.axis([-0.85389096, 0.52045195, -0.85389096, 0.52045195])
plt.show()
if __name__ == '__main__':
plot_orthogonal()
# plot_2d()
# basic_linear()
# basic_curve()
# multi_curve()
# multi_figure()
# multi_figure_two()
# histogram()
# histogram_two()
pass
Morty Proxy This is a proxified and sanitized view of the page, visit original site.