2022年12月18日 星期日

Python 量子運算(六):角度與弧度

Python 量子運算(六):角度與弧度

2022/11/28

-----


Fig. 6.1. Degree and radian.

-----

代碼 6.1


 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
# Program 6.1:Degree and radian
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt


def DrawSubplot(N, i, j):
    splt_number = i * N + j + 1
    ax = plt.subplot(N, N, splt_number)

    # basic setting
    theta = np.linspace(0, 2*np.pi, 100)
    axis = np.linspace(-1, 1, 100)
    zero = axis * 0
    radius = 0.7
    x1 = radius*np.cos(theta)
    y1 = radius*np.sin(theta)

    # basic plotting
    ax.plot(axis, zero, 'k')  # y = 0(x_axis)
    ax.plot(zero, axis, 'k')  # x = 0(y_axis)
    ax.plot(x1, y1, 'k')      # cicle

    # vector setting
    coordinates = [0, 0]      # original point
    splt_radian = [10*(2*np.pi/360), np.pi/6, 1, np.pi/3]
    splt_title = [r"$10^{\circ}$", r"$30^{\circ}$", r"$1rad$", r"$60^{\circ}$"]
    splt_index = ['(a)', '(b)', '(c)', '(d)']

    # vector plotting
    vector_p = splt_radian[splt_number-1]
    vector = [radius*np.cos(vector_p), radius*np.sin(vector_p)]  # direction
    plt.quiver(coordinates[0], coordinates[1], vector[0], vector[1],
               scale=2, color='r')

    ax.set_aspect(1)  # height : width
    ax.set_axis_off()

    if splt_number == 2:
        ax.text(1.1, -0.15, r"$Z$")
        ax.text(0.1, 1, r"$X$")
        ax.text(0.35, 0.03, r"$\theta$", fontsize=40)
    elif splt_number == 4:
        ax.text(1.1, -0.15, r"$X$")
        ax.text(0.1, 1, r"$Y$")
        ax.text(0.2, 0.1, r"$\phi$", fontsize=40)
    else:
        ax.text(1.1, -0.15, r"$X$")
        ax.text(0.1, 1, r"$Y$")

    ax.text(radius+0.1, -0.15, r"$A$")
    ax.text(radius*np.cos(vector_p)+0.1, radius*np.sin(vector_p), r"$B$")

    plt.title(splt_title[splt_number-1], fontsize=80)
    ax.text(0.1, -1, splt_index[splt_number-1])
    return


mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'
mpl.rcParams['font.size'] = 20
fig = plt.figure(figsize=(16, 16))

N = 2
for i in range(N):
    for j in range(N):
        DrawSubplot(N, i, j)

# plt.savefig('/content/drive/My Drive/pqc/0006_001.png')
plt.show()

解說:


-----

References


[1] 自定義View 基礎- 角度與弧度| Welcome to sunzn's Blog

https://www.sunzn.com/2017/08/21/%E8%87%AA%E5%AE%9A%E4%B9%89-View-%E5%9F%BA%E7%A1%80-%E8%A7%92%E5%BA%A6%E4%B8%8E%E5%BC%A7%E5%BA%A6/


[2] 如何在 Matplotlib 中繪製圓 | D棧 - Delft Stack

https://www.delftstack.com/zh-tw/howto/matplotlib/how-to-plot-a-circle-in-matplotlib/


[3] Matplotlib 中的箭袋圖 | D棧 - Delft Stack

https://www.delftstack.com/zh-tw/howto/matplotlib/create-quiver-diagram-in-matplotlib/


[4] Matplotlib 中的箭袋圖 - GeeksforGeeks

https://www.geeksforgeeks.org/quiver-plot-in-matplotlib/


[5] matplotlib.pyplot.quiver — Matplotlib 3.6.2 documentation

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html


[6] 在 Matplotlib 中新增子圖 | D棧 - Delft Stack

https://www.delftstack.com/zh-tw/howto/matplotlib/add-subplot-to-a-figure-matplotlib/


[7] 如何在 Matplotlib 中改變子圖的大小和間距 | D棧 - Delft Stack

https://www.delftstack.com/zh-tw/howto/matplotlib/how-to-improve-subplot-size-or-spacing-with-many-subplots-in-matplotlib/


[8] LaTeX angle symbols (degree, radian) - Rollpie

https://www.rollpie.com/post/475

-----

Python 量子運算(目錄)

https://mandhistory.blogspot.com/2022/01/quantum-computing.html

-----

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。