Python_Matplotlib - 1. Join styles
https://matplotlib.org/gallery/api/joinstyle.html#sphx-glr-gallery-api-joinstyle-py
====== 程式碼 + 註解 ==========
# https://matplotlib.org/gallery/api/joinstyle.html#sphx-glr-gallery-api-joinstyle-py
"""
===========
Join styles
===========
Illustrate the three different join styles.
"""
import numpy as np
import matplotlib.pyplot as plt
def plot_angle(ax, x, y, angle, style): # 定義一個畫圖的 def
phi = np.radians(angle) # np.radians(180) = 3.14159265
# np.radians(8) = 0.139626340
xx = [x + .5, x, x + .5*np.cos(phi)] # x = 0 y =0 ==> xx =[0.5,0,0+0.5*cos(phi)]
yy = [y, y, y + .5*np.sin(phi)] # yy = 圖形 3 點 Y座標位置
ax.plot(xx, yy, lw=8, color='blue', solid_joinstyle=style)
ax.plot(xx[1:], yy[1:], lw=1, color='orange') # 後 2 點
#ax.plot(xx[1::-1], yy[1::-1], lw=1, color='black') # 前 2 點
ax.plot(xx[:2], yy[:2], lw=1, color='black') # 前 2 點
ax.plot(xx[1:2], yy[1:2], 'o', color='red', markersize=3) # 紅點 3點裡面的第2點
ax.text(x, y + .2, '%.0f degrees' % angle)
fig, ax = plt.subplots() # fig, ax = plt.subplots() => fig = plt.figure() + ax = fig.add_subplot(111)
ax.set_title('Join style')
for x, style in enumerate((('miter', 'round', 'bevel'))):
ax.text(x, 5, style) # x 依順序 => 0 1 2 , style 依順序 => 'miter', 'round', 'bevel'
for i in range(5):
plot_angle(ax, x, i, pow(2.0, 3 + i), style) # 調用 plot_angle i 依順序 => 0 1 2 3 4 pow : 函数是计算x的y次方
# loop = 1 時 x = 0 i = 0 angle = 2^3 = 8
# loop = 2 時 x = 0 i = 1 angle = 2^4 = 16
# loop = 2 時 x = 0 i = 2 angle = 2^5 = 32
ax.set_xlim(-.5, 2.75)
ax.set_ylim(-.5, 5.5) # 設定:界線
plt.show()
================
xx 和 yy 的 3 點