Visualize-ML / Book3_Elements-of-Mathematics

Book_3_《数学要素》 | 鸢尾花书:从加减乘除到机器学习;上架;欢迎继续纠错,纠错多的同学还会有赠书!
6.05k stars 1.04k forks source link

Book3_Ch14_数列__PAGE11_缺少部分代码 #115

Closed lang07123 closed 3 months ago

lang07123 commented 12 months ago

图片 只显示了一张图片, 没有其它的图,

附修改后的代码:

###############
# Authored by Weisheng Jiang
# Book 3  |  From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############

# Bk3_Ch14_02

import numpy as np
from matplotlib import pyplot as plt

a = 1    # initial term
n = 50   # number of terms
q_list = [1.1, 1, 0.9, -0.9, -1, -1.1]

# initial figure
fig = plt.figure(figsize=(18, 8))

for pos, q in enumerate(q_list):
    # Generate geometric progression, GP, sequence
    GP_sequence = [a*q**i for i in range(n)]
    index       = np.arange(1, n + 1, 1)

    # split the figures
    ax = fig.add_subplot(2, 3, pos+1)

    # add the title and label
    ax.set_title(F'q = {q}', loc="left")
    ax.set_xlabel("Index, $k$") 
    ax.set_ylabel("Term, $a_k$")

    # plot
    ax.plot(index, GP_sequence, marker='.', markersize=6, linestyle='None')

    # setup the grid line
    ax.grid(linestyle='--', linewidth=0.25, color=[0.5, 0.5, 0.5])

plt.show()
Visualize-ML commented 11 months ago

你是对的,本来是想让读者自己探索,在原来代码上修改。下一版应该采用子图方式,也就是你建议的代码。请继续批评指正。

On Mon, Jul 24, 2023 at 3:17 AM lang07123 @.***> wrote:

[image: 图片] https://user-images.githubusercontent.com/7733095/255512922-99f92b70-82ea-4610-9f0e-6840e69993dd.png 只显示了一张图片, 没有其它的图,

附修改后的代码:

###############

Authored by Weisheng Jiang

Book 3 | From Basic Arithmetic to Machine Learning

Published and copyrighted by Tsinghua University Press

Beijing, China, 2022

###############

Bk3_Ch14_02

import numpy as np from matplotlib import pyplot as plt

a = 1 # initial term n = 50 # number of terms q_list = [1.1, 1, 0.9, -0.9, -1, -1.1]

fig = plt.figure(figsize=(20, 8))

for pos, q in enumerate(q_list):

Generate geometric progression, GP, sequence

GP_sequence = [a*q**i for i in range(n)]
index = np.arange(1, n + 1, 1)

ax = fig.add_subplot(2, 3, pos+1)
ax.set_xlabel("Index, $k$")
ax.set_ylabel("Term, $a_k$")
ax.plot(index, GP_sequence, marker='.', markersize=6, linestyle='None')
ax.grid(linestyle='--', linewidth=0.25, color=[0.5, 0.5, 0.5])

plt.show()

— Reply to this email directly, view it on GitHub https://github.com/Visualize-ML/Book3_Elements-of-Mathematics/issues/115, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZHC6V7CYXSDHLQMXS4XFGDXRYOPBANCNFSM6AAAAAA2VES7UM . You are receiving this because you are subscribed to this thread.Message ID: @.***>