teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

7

説明を追加

2021/08/23 16:23

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -23,7 +23,7 @@
23
23
  inputVal0=readadc(0,SPICLK,SPIMOSI,SPIMISO,SPICS)
24
24
  の行の直前(try:の直後)に1箇所あればよいはず
25
25
  - finally 節はエラーが出ても出なくても必ず実行される。try 節の sleep(1) で1秒スリープし、さらに finally 節の sleep(1) で1秒スリープする結果、2秒間隔で while ループが実行されることになる。それでよいのかどうか。
26
- よくない場合は、finally 節を削除して、except 節の continue の前に sleep(1) を入れ
26
+ よくない場合は、finally 節を削除して、finally 節の sleep(1) は except 節の continue の前に移動す
27
27
  - except 節は複数指定できるので、以下のような書き方ができる
28
28
  ```python
29
29
  while True:

6

説明を追加

2021/08/23 16:23

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  - plt.figure(figsize=(12.8, 4.8))の行は不要
4
4
  - 代わりに `ax.cla()` の1行をその位置に挿入する
5
- - plt.gca().〜 は `ax`.〜 に置き換えて以下のようにする(書き換えなくても動くが、関数にするならこのほうがプログラムが明になる)
5
+ - plt.gca().〜 は `ax`.〜 に置き換えて以下のようにする(書き換えなくても動くが、関数にするならこのほうがプログラムの意図※が明になる)
6
6
  ax.xaxis.set_major_locator(mdates.HourLocator(interval=1))
7
7
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
8
8
  ax.set_xlim(xmin=datetime.datetime(d_today.year, d_today.month, d_today.day, 7, 0),xmax=dt_end)
9
9
  ax.set_yticks([0, 1])
10
+ ※ プログラムの意図:figure(fig)、Axes(ax)は最初にひとつだけ作って、関数では常にそれを引数で受け取って使い回すということ
10
11
  - 上と同じ理由で plt.bar(x,y,width=0.0007) も
11
12
  `ax.bar(x,y,width=0.0007)`
12
13
  とした方が良い

5

説明を追加

2021/08/23 16:04

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  - plt.figure(figsize=(12.8, 4.8))の行は不要
4
4
  - 代わりに `ax.cla()` の1行をその位置に挿入する
5
- - plt.gca().〜 は `ax`.〜 に置き換えて以下のようにする
5
+ - plt.gca().〜 は `ax`.〜 に置き換えて以下のようにする(書き換えなくても動くが、関数にするならこのほうがプログラムが明快になる)
6
6
  ax.xaxis.set_major_locator(mdates.HourLocator(interval=1))
7
7
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
8
8
  ax.set_xlim(xmin=datetime.datetime(d_today.year, d_today.month, d_today.day, 7, 0),xmax=dt_end)
9
9
  ax.set_yticks([0, 1])
10
+ - 上と同じ理由で plt.bar(x,y,width=0.0007) も
11
+ `ax.bar(x,y,width=0.0007)`
12
+ とした方が良い
10
13
 
11
14
  **エラーメッセージについて:**
12
15
  - エラーメッセージではなく警告メッセージ

4

説明の語句を追加

2021/08/23 15:54

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -17,7 +17,7 @@
17
17
  - from io import StringIO は不要
18
18
  - start=time.time() が2箇所にあるが、
19
19
  inputVal0=readadc(0,SPICLK,SPIMOSI,SPIMISO,SPICS)
20
- の行の直前に1箇所あればよいはず
20
+ の行の直前(try:の直後)に1箇所あればよいはず
21
21
  - finally 節はエラーが出ても出なくても必ず実行される。try 節の sleep(1) で1秒スリープし、さらに finally 節の sleep(1) で1秒スリープする結果、2秒間隔で while ループが実行されることになる。それでよいのかどうか。
22
22
  よくない場合は、finally 節を削除して、except 節の continue の前に sleep(1) を入れる
23
23
  - except 節は複数指定できるので、以下のような書き方ができる

3

回答の微修正と回答の追加

2021/08/23 15:25

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  - plt.figure(figsize=(12.8, 4.8))の行は不要
4
4
  - 代わりに `ax.cla()` の1行をその位置に挿入する
5
- - plt.gca().〜 は `ax`.〜 に置き換える。結果として以下のように
5
+ - plt.gca().〜 は `ax`.〜 に置き換えて以下のように
6
6
  ax.xaxis.set_major_locator(mdates.HourLocator(interval=1))
7
7
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
8
8
  ax.set_xlim(xmin=datetime.datetime(d_today.year, d_today.month, d_today.day, 7, 0),xmax=dt_end)
@@ -15,6 +15,18 @@
15
15
 
16
16
  **その他:**
17
17
  - from io import StringIO は不要
18
+ - start=time.time() が2箇所にあるが、
18
- - start=time.time() が2箇所にあるが、inputVal0=readadc(0,SPICLK,SPIMOSI,SPIMISO,SPICS) の行の直前に1箇所あればよいはず
19
+ inputVal0=readadc(0,SPICLK,SPIMOSI,SPIMISO,SPICS)
20
+ の行の直前に1箇所あればよいはず
19
- - finally 節はエラーが出ても出なくても必ず実行されるので、FileNotFoundErrorが出ていない間は、try 節の sleep(1) finally 節の sleep(1) 2秒間隔で while ループが実行される。それでよいのかどうか。
21
+ - finally 節はエラーが出ても出なくても必ず実行されるtry 節の sleep(1) で1秒スリープし、さらに finally 節の sleep(1) で1秒スリープする結果、2秒間隔で while ループが実行されることになる。それでよいのかどうか。
20
- よくない場合は、finally 節を削除して、except 節の continue の前に sleep(1) を入れる
22
+ よくない場合は、finally 節を削除して、except 節の continue の前に sleep(1) を入れる
23
+ - except 節は複数指定できるので、以下のような書き方ができる
24
+ ```python
25
+ while True:
26
+ try:
27
+ ...
28
+ except FileNotFoundError:
29
+ continue
30
+ except KeyboardInterrupt:
31
+ break # ctrl+c でループを抜ける
32
+ ```

2

微細な修正

2021/08/23 15:21

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  - plt.figure(figsize=(12.8, 4.8))の行は不要
4
4
  - 代わりに `ax.cla()` の1行をその位置に挿入する
5
- - plt.gca() の箇所は `ax` に置き換える。結果として以下のようになる
5
+ - plt.gca().〜 は `ax`.〜 に置き換える。結果として以下のようになる
6
6
  ax.xaxis.set_major_locator(mdates.HourLocator(interval=1))
7
7
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
8
8
  ax.set_xlim(xmin=datetime.datetime(d_today.year, d_today.month, d_today.day, 7, 0),xmax=dt_end)

1

微細な修正

2021/08/23 14:08

投稿

etherbeg
etherbeg

スコア1195

answer CHANGED
@@ -1,4 +1,4 @@
1
- **def plot_operation()関数について:**
1
+ **plot_operation()関数について:**
2
2
 
3
3
  - plt.figure(figsize=(12.8, 4.8))の行は不要
4
4
  - 代わりに `ax.cla()` の1行をその位置に挿入する