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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
4+10
import matplotlib.pyplot as plt import numpy as np
np.random.seed(19680801)
fig, ax = plt.subplots()
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim') y_pos = np.arange(len(people)) performance = 3 + 10 * np.random.rand(len(people)) error = np.random.rand(len(people))
ax.barh(y_pos, performance, xerr=error, align='center') ax.set_yticks(y_pos, labels=people) ax.invert_yaxis() ax.set_xlabel('Performance') ax.set_title('How fast do you want to go today?')
plt.show()
import matplotlib.pyplot as plt import numpy as np
from matplotlib.patches import PathPatch from matplotlib.path import Path
N = 400 t = np.linspace(0, 2 * np.pi, N) r = 0.5 + np.cos(t) x, y = r * np.cos(t), r * np.sin(t)
fig, ax = plt.subplots() ax.plot(x, y, "k") ax.set(aspect=1)
def draw_error_band(ax, x, y, err, **kwargs): dx = np.concatenate([[x[1] - x[0]], x[2:] - x[:-2], [x[-1] - x[-2]]]) dy = np.concatenate([[y[1] - y[0]], y[2:] - y[:-2], [y[-1] - y[-2]]]) l = np.hypot(dx, dy) nx = dy / l ny = -dx / l
xp = x + nx * err yp = y + ny * err xn = x - nx * err yn = y - ny * err
vertices = np.block([[xp, xn[::-1]], [yp, yn[::-1]]]).T codes = np.full(len(vertices), Path.LINETO) codes[0] = codes[len(xp)] = Path.MOVETO path = Path(vertices, codes) ax.add_patch(PathPatch(path, **kwargs))
_, axs = plt.subplots(1, 2, layout='constrained', sharex=True, sharey=True) errs = [ (axs[0], "constant error", 0.05), (axs[1], "variable error", 0.05 * np.sin(2 * t) ** 2 + 0.04), ] for i, (ax, title, err) in enumerate(errs): ax.set(title=title, aspect=1, xticks=[], yticks=[]) ax.plot(x, y, "k") draw_error_band(ax, x, y, err=err, facecolor=f"C{i}", edgecolor="none", alpha=.3)
plt.show()
x1 = False
type(x1)
x2 = 3 type(x2)
x3 = 3.3 type(x3)
x4 = "名字" type(x4)
print(1, 2, 3, 4)
print(1, 2, 3, 4, end= "|", sep= '|')
print(1, 2, 3, 4, end= "|")
print("將華氏轉成攝氏溫度")
f = float(input("請輸入華氏溫度"))
c = (f-32)*(5/9)
print("攝氏溫度為:" , c)
|