質問編集履歴

6

追記

2017/04/13 09:25

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -51,6 +51,20 @@
51
51
 
52
52
 
53
53
  ```python
54
+
55
+ from flask import Flask,send_file
56
+
57
+ from matplotlib import pyplot as plt
58
+
59
+ from matplotlib.font_manager import FontProperties
60
+
61
+ import numpy as np
62
+
63
+ import random
64
+
65
+ from io import BytesIO
66
+
67
+
54
68
 
55
69
  class Image:
56
70
 

5

修正

2017/04/13 09:25

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -146,6 +146,10 @@
146
146
 
147
147
  def main():
148
148
 
149
+ image = "sample.png"
150
+
151
+ image2 = "sample_circle.png"
152
+
149
153
  return render_template("index.html",image=image,image2=image2)
150
154
 
151
155
 

4

修正

2017/04/13 09:24

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -154,7 +154,7 @@
154
154
 
155
155
  def img():
156
156
 
157
- return plot.line_graph(data)
157
+ return plot.line_graph()
158
158
 
159
159
 
160
160
 
@@ -162,7 +162,7 @@
162
162
 
163
163
  def sircle():
164
164
 
165
- return plot.circle_graph(data)
165
+ return plot.circle_graph()
166
166
 
167
167
 
168
168
 

3

修正

2017/04/13 09:23

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -154,8 +154,6 @@
154
154
 
155
155
  def img():
156
156
 
157
- data = [i*i**2*random.randint(100,900) for i in range(10)]
158
-
159
157
  return plot.line_graph(data)
160
158
 
161
159
 
@@ -163,8 +161,6 @@
163
161
  @app.route("/sample_circle.png")
164
162
 
165
163
  def sircle():
166
-
167
- data = np.array([100, 200, 300, 400, 500])
168
164
 
169
165
  return plot.circle_graph(data)
170
166
 

2

追記

2017/04/13 09:23

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
 
44
44
 
45
- ##実際のコード
45
+ ##plot.py(オリジナル)
46
46
 
47
47
 
48
48
 
@@ -50,7 +50,7 @@
50
50
 
51
51
 
52
52
 
53
- ```py3
53
+ ```python
54
54
 
55
55
  class Image:
56
56
 
@@ -121,3 +121,57 @@
121
121
  return Image.generate_img(image)
122
122
 
123
123
  ```
124
+
125
+
126
+
127
+ ##Flaskのmain.py
128
+
129
+
130
+
131
+ ```python
132
+
133
+ from flask import Flask,render_template,send_file
134
+
135
+ import os
136
+
137
+ import plot # オリジナル
138
+
139
+
140
+
141
+ app = Flask(__name__)
142
+
143
+
144
+
145
+ @app.route("/")
146
+
147
+ def main():
148
+
149
+ return render_template("index.html",image=image,image2=image2)
150
+
151
+
152
+
153
+ @app.route("/sample.png")
154
+
155
+ def img():
156
+
157
+ data = [i*i**2*random.randint(100,900) for i in range(10)]
158
+
159
+ return plot.line_graph(data)
160
+
161
+
162
+
163
+ @app.route("/sample_circle.png")
164
+
165
+ def sircle():
166
+
167
+ data = np.array([100, 200, 300, 400, 500])
168
+
169
+ return plot.circle_graph(data)
170
+
171
+
172
+
173
+ if __name__ == "__main__":
174
+
175
+ app.run(debug=True)
176
+
177
+ ```

1

追記

2017/04/13 09:22

投稿

starrow1103
starrow1103

スコア137

test CHANGED
File without changes
test CHANGED
@@ -51,6 +51,20 @@
51
51
 
52
52
 
53
53
  ```py3
54
+
55
+ class Image:
56
+
57
+ def generate_img(image):
58
+
59
+ plt.savefig(image, format='png')
60
+
61
+ image.seek(0)
62
+
63
+ return send_file(image,attachment_filename="hoge.png",as_attachment=True)
64
+
65
+ #↑こいつをflaskのmain.pyでうけとって、<img src="">に使ってる
66
+
67
+
54
68
 
55
69
  def line_graph():
56
70