forked from Visualize-ML/Book3_Elements-of-Mathematics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBk3_Ch12_01.py
More file actions
68 lines (54 loc) · 1.29 KB
/
Bk3_Ch12_01.py
File metadata and controls
68 lines (54 loc) · 1.29 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
###############
# Authored by Weisheng Jiang
# Book 3 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
# Bk3_Ch12_01
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0.1, 10, 100)
x = np.linspace(0.1, 1000, 100)
# x log scale
f1 = 10**x1
f2 = x1
f3 = np.log(x)
fig, ax = plt.subplots()
plt.plot(x1,f1,color = 'r')
plt.plot(x1,f2,color = 'k')
plt.plot(x,f3,color = 'b')
plt.xscale("log")
plt.ylim((-0.5,10))
plt.grid()
plt.tight_layout()
ax.set_box_aspect(1)
# y log scale
f1 = 10**x1
f2 = x1
f3 = np.log(x1)
fig, ax = plt.subplots()
plt.plot(x1,f1,color = 'r')
plt.plot(x1,f2,color = 'k')
plt.plot(x1,f3,color = 'b')
plt.yscale("log")
plt.ylim((0.1,1000))
plt.grid()
plt.tight_layout()
ax.set_box_aspect(1)
# x and y log scale
x_log = np.logspace(np.log(0.1), np.log(1000), num=100,
endpoint=True, base=10.0)
f1 = 10**x_log
f2 = x_log
f3 = np.log(x_log)
fig, ax = plt.subplots()
plt.plot(x_log,f1,color = 'r')
plt.plot(x_log,f2,color = 'k')
plt.plot(x_log,f3,color = 'b')
plt.yscale("log")
plt.xscale("log")
plt.ylim((0.1,1000))
plt.xlim((0.1,1000))
plt.grid()
plt.tight_layout()
ax.set_box_aspect(1)