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

回答編集履歴

2

修正

2021/01/28 10:47

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -1,12 +1,11 @@
1
1
  matplotlib の Figure を画像化して base64 文字列に変換し、[インライン画像](https://dev.classmethod.jp/articles/image-performance-tuning-03/) として、テンプレート上に `img` タグで表示すればいいと思います。
2
2
 
3
- index.html
3
+ templates/index.html
4
4
  ```
5
5
  <img src="data:image/png;base64,{{ img }}" />
6
6
  ```
7
7
 
8
- 以下が matplotlib で作成した Figure を base64 に変換するコードです。
8
+ main.py
9
-
10
9
  ```python
11
10
  import base64
12
11
  from io import BytesIO

1

修正

2021/01/28 10:47

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -63,4 +63,6 @@
63
63
 
64
64
  ----
65
65
 
66
- [Github](https://github.com/nekobean/snippets/tree/master/319114) に動作するコード全体を載せましたので、なにか疑問点があったらコメントしてください。
66
+ [Github](https://github.com/nekobean/snippets/tree/master/319114) に動作するコード全体を載せましたので、なにか疑問点があったらコメントしてください。
67
+
68
+ ![イメージ説明](821ef6c20830e833c6f2eda03fa90fea.png)