質問編集履歴
2
改行によりソースコードが表示されておりませんでした。
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,21 +33,17 @@
|
|
33
33
|
|
34
34
|
#for day, gdf in df.groupby(pd.Grouper(key='Time', freq='D')):
|
35
35
|
for day, gdf in df.groupby([df['time'].dt.date]):
|
36
|
+
gdf = gdf.copy() # Suppress SettingWithCopyWarning
|
36
37
|
|
37
|
-
|
38
|
+
gdf['time'] = pd.to_datetime(gdf['time'].dt.strftime(f'{org_date} %H:%M'))
|
38
|
-
|
39
|
+
gdf.plot( ax=ax, x='time', y='IGT / mg/dL', label=day.strftime('%Y-%m-%d'))
|
39
40
|
|
40
|
-
gdf['time'] = pd.to_datetime(gdf['time'].dt.strftime(f'{org_date} %H:%M'))
|
41
|
-
|
42
|
-
gdf.plot( ax=ax, x='time', y='IGT / mg/dL', label=day.strftime('%Y-%m-%d'))
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
ax.set_xlim(xlim)
|
46
|
-
|
42
|
+
ax.xaxis.set_major_locator(md.HourLocator(interval = 1)) # 1hour
|
47
|
-
|
43
|
+
ax.xaxis.set_major_formatter(md.DateFormatter("%H:%M")) # hour:min
|
48
|
-
|
44
|
+
ax.grid(which = "major", axis = "x", color = "black", alpha = 0.4,
|
49
45
|
linestyle = "--", linewidth = 0.2)
|
50
|
-
|
46
|
+
ax.grid(which = "major", axis = "y", color = "black", alpha = 0.4,
|
51
47
|
linestyle = "--", linewidth = 0.2)
|
52
48
|
|
53
49
|
plt.ylim(40,220)
|
1
表示をまちがえておりました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,54 +7,51 @@
|
|
7
7
|
2. 特定の日にちデータだけ太線で示す。
|
8
8
|
3. すべてのフォントを一括でboldで示す。
|
9
9
|
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-25/5b7039ce-e84a-402d-a6f5-e0f2a01c0dff.png)
|
10
|
+
|
11
|
+
###該当のcsvデータ
|
12
|
+
https://firestorage.jp/download/5c2e9cf05118ca0041b2f25fb1e72b8bd3366d5a
|
13
|
+
|
10
14
|
### 該当のソースコード
|
11
15
|
import pandas as pd
|
12
16
|
import matplotlib.pyplot as plt
|
13
17
|
import matplotlib.dates as md
|
14
18
|
from datetime import datetime, timedelta
|
15
19
|
|
16
|
-
# 検証データ
|
17
20
|
df = pd.read_csv('hada_glucose_2022-8-25_present3.csv', parse_dates=['time'])
|
18
21
|
|
19
|
-
# x軸(時刻)の範囲制限用
|
20
|
-
org_date = '2022-1-01'
|
22
|
+
org_date = '2022-1-01'
|
21
23
|
st = datetime.strptime(org_date, '%Y-%m-%d')
|
22
24
|
xlim = [pd.to_datetime(st), pd.to_datetime(st+timedelta(days=1))]
|
23
25
|
|
24
|
-
fig, ax = plt.subplots(figsize=(17,9))
|
26
|
+
fig, ax = plt.subplots(figsize=(17,9))
|
25
27
|
|
26
|
-
|
28
|
+
|
27
|
-
plt.rcParams["font.family"] = "Helvetica"
|
29
|
+
plt.rcParams["font.family"] = "Helvetica"
|
28
|
-
plt.rcParams["font.size"] = 12
|
30
|
+
plt.rcParams["font.size"] = 12
|
29
31
|
ax.set_xlabel("Time", fontweight='bold')
|
30
32
|
ax.set_ylabel("Interstitial glucose level / mg/dL", fontweight='bold')
|
31
33
|
|
32
|
-
# 日毎にグループ化
|
33
|
-
#for day, gdf in df.groupby(pd.Grouper(key='Time', freq='D')):
|
34
|
+
#for day, gdf in df.groupby(pd.Grouper(key='Time', freq='D')):
|
34
|
-
for day, gdf in df.groupby([df['time'].dt.date]):
|
35
|
+
for day, gdf in df.groupby([df['time'].dt.date]):
|
35
36
|
|
36
37
|
gdf = gdf.copy() # Suppress SettingWithCopyWarning
|
37
38
|
|
38
|
-
|
39
|
+
|
39
40
|
gdf['time'] = pd.to_datetime(gdf['time'].dt.strftime(f'{org_date} %H:%M'))
|
40
41
|
|
41
42
|
gdf.plot( ax=ax, x='time', y='IGT / mg/dL', label=day.strftime('%Y-%m-%d'))
|
42
43
|
|
43
|
-
|
44
|
+
|
44
45
|
ax.set_xlim(xlim)
|
45
46
|
ax.xaxis.set_major_locator(md.HourLocator(interval = 1)) # 1hour
|
46
47
|
ax.xaxis.set_major_formatter(md.DateFormatter("%H:%M")) # hour:min
|
47
48
|
ax.grid(which = "major", axis = "x", color = "black", alpha = 0.4,
|
48
|
-
linestyle = "--", linewidth = 0.2)
|
49
|
+
linestyle = "--", linewidth = 0.2)
|
49
50
|
ax.grid(which = "major", axis = "y", color = "black", alpha = 0.4,
|
50
|
-
linestyle = "--", linewidth = 0.2)
|
51
|
+
linestyle = "--", linewidth = 0.2)
|
51
52
|
|
52
53
|
plt.ylim(40,220)
|
53
|
-
|
54
|
-
# 凡例の調整
|
55
54
|
plt.legend(bbox_to_anchor=(1.01, 1), loc='upper left', borderaxespad=0, fontsize=12)
|
56
|
-
|
57
|
-
# グラフをxxx.pngという名前のファイルで解像度いくつで保存
|
58
55
|
plt.savefig("hada_glucose_2022-8-25_present3.png",dpi=400)
|
59
56
|
|
60
57
|
plt.show()
|