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

質問編集履歴

6

追記

2017/04/13 09:25

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -25,6 +25,13 @@
25
25
  ちょっとぐちゃぐちゃしてますが、上の関数が線グラフ、下の関数が円グラフです
26
26
 
27
27
  ```python
28
+ from flask import Flask,send_file
29
+ from matplotlib import pyplot as plt
30
+ from matplotlib.font_manager import FontProperties
31
+ import numpy as np
32
+ import random
33
+ from io import BytesIO
34
+
28
35
  class Image:
29
36
  def generate_img(image):
30
37
  plt.savefig(image, format='png')

5

修正

2017/04/13 09:25

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -72,6 +72,8 @@
72
72
 
73
73
  @app.route("/")
74
74
  def main():
75
+ image = "sample.png"
76
+ image2 = "sample_circle.png"
75
77
  return render_template("index.html",image=image,image2=image2)
76
78
 
77
79
  @app.route("/sample.png")

4

修正

2017/04/13 09:24

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -76,11 +76,11 @@
76
76
 
77
77
  @app.route("/sample.png")
78
78
  def img():
79
- return plot.line_graph(data)
79
+ return plot.line_graph()
80
80
 
81
81
  @app.route("/sample_circle.png")
82
82
  def sircle():
83
- return plot.circle_graph(data)
83
+ return plot.circle_graph()
84
84
 
85
85
  if __name__ == "__main__":
86
86
  app.run(debug=True)

3

修正

2017/04/13 09:23

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -76,12 +76,10 @@
76
76
 
77
77
  @app.route("/sample.png")
78
78
  def img():
79
- data = [i*i**2*random.randint(100,900) for i in range(10)]
80
79
  return plot.line_graph(data)
81
80
 
82
81
  @app.route("/sample_circle.png")
83
82
  def sircle():
84
- data = np.array([100, 200, 300, 400, 500])
85
83
  return plot.circle_graph(data)
86
84
 
87
85
  if __name__ == "__main__":

2

追記

2017/04/13 09:23

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -20,11 +20,11 @@
20
20
  解決策のご教授をよろしくおねがいいたします・・・。
21
21
 
22
22
 
23
- ##実際のコード
23
+ ##plot.py(オリジナル)
24
24
 
25
25
  ちょっとぐちゃぐちゃしてますが、上の関数が線グラフ、下の関数が円グラフです
26
26
 
27
- ```py3
27
+ ```python
28
28
  class Image:
29
29
  def generate_img(image):
30
30
  plt.savefig(image, format='png')
@@ -59,4 +59,31 @@
59
59
  #グラフをオブジェクトに保管
60
60
  image = BytesIO()
61
61
  return Image.generate_img(image)
62
+ ```
63
+
64
+ ##Flaskのmain.py
65
+
66
+ ```python
67
+ from flask import Flask,render_template,send_file
68
+ import os
69
+ import plot # オリジナル
70
+
71
+ app = Flask(__name__)
72
+
73
+ @app.route("/")
74
+ def main():
75
+ return render_template("index.html",image=image,image2=image2)
76
+
77
+ @app.route("/sample.png")
78
+ def img():
79
+ data = [i*i**2*random.randint(100,900) for i in range(10)]
80
+ return plot.line_graph(data)
81
+
82
+ @app.route("/sample_circle.png")
83
+ def sircle():
84
+ data = np.array([100, 200, 300, 400, 500])
85
+ return plot.circle_graph(data)
86
+
87
+ if __name__ == "__main__":
88
+ app.run(debug=True)
62
89
  ```

1

追記

2017/04/13 09:22

投稿

starrow1103
starrow1103

スコア137

title CHANGED
File without changes
body CHANGED
@@ -25,6 +25,13 @@
25
25
  ちょっとぐちゃぐちゃしてますが、上の関数が線グラフ、下の関数が円グラフです
26
26
 
27
27
  ```py3
28
+ class Image:
29
+ def generate_img(image):
30
+ plt.savefig(image, format='png')
31
+ image.seek(0)
32
+ return send_file(image,attachment_filename="hoge.png",as_attachment=True)
33
+ #↑こいつをflaskのmain.pyでうけとって、<img src="">に使ってる
34
+
28
35
  def line_graph():
29
36
  data = [i*i**2*random.randint(100,900) for i in range(10)]
30
37
  plt.figure(figsize=(7,5))#グラフの縦横比