回答編集履歴

2

Update

2022/03/06 01:14

投稿

melian
melian

スコア20001

test CHANGED
@@ -20,6 +20,7 @@
20
20
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%-m月'))
21
21
  ax.grid(axis='y')
22
22
  ax.legend(loc='upper left')
23
+ ax.tick_params(top=False)
23
24
  ax.set_frame_on(False)
24
25
 
25
26
  # 余りは非表示
@@ -28,5 +29,4 @@
28
29
  fig.tight_layout(pad=2.0)
29
30
  plt.show()
30
31
  ```
31
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-03-06/6d7c37a8-ad8c-4a5f-a0be-2b0dae875626.png)
32
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-03-06/a24a451a-502f-4012-a064-db865f6b9ac2.png)
32
-

1

Update

2022/03/06 00:35

投稿

melian
melian

スコア20001

test CHANGED
@@ -7,10 +7,26 @@
7
7
  plt.rcParams['font.family'] = 'MS Gothic'
8
8
 
9
9
  df = pd.read_csv('熊本.csv', parse_dates=['年月'], index_col='年月')
10
+ fig, axes = plt.subplots(3, 2, figsize=(10, 10))
11
+ axes = axes.flatten()
10
- for year in range(1980, 2021, 10):
12
+ years = range(1980, 2021, 10)
13
+ for year, ax in zip(years, axes):
14
+ df[df.index.year==year].plot(
15
+ y = '日の平均気温(℃)', x_compat=True, xlabel='',
11
- h1, = plt.plot(df[df.index.year==year]['日の平均気温(℃)'],label=f'{year}/1~{year}/12')
16
+ label=f'{year}/1~{year}/12', title=f'{year}年 平均気温(℃)', ax=ax)
17
+ ax.set_ylim([0., 32.])
18
+ ax.xaxis.set_tick_params(reset=True)
12
- plt.gca().xaxis.set_major_locator(mdates.MonthLocator())
19
+ ax.xaxis.set_major_locator(mdates.MonthLocator())
13
- plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%-m月'))
20
+ ax.xaxis.set_major_formatter(mdates.DateFormatter('%-m月'))
21
+ ax.grid(axis='y')
14
- plt.legend(handles=[h1])
22
+ ax.legend(loc='upper left')
23
+ ax.set_frame_on(False)
24
+
25
+ # 余りは非表示
26
+ axes[-1].axis('off')
27
+
28
+ fig.tight_layout(pad=2.0)
15
- plt.show()
29
+ plt.show()
16
30
  ```
31
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-03-06/6d7c37a8-ad8c-4a5f-a0be-2b0dae875626.png)
32
+