年月と値がグラフでうまく表示できません。
views.pyに
def past_result(request): return render(request, 'result.html', {'chart': _view_plot()}) def _view_plot(): left = np.array([2016-04-10, 2016-10-05, 2016-10-10, 2016-10-11, 2016-12-10]) height = np.array([100, 300, 200, 500, 400]) plt.plot(left, height) jpg_image_buffer = cStringIO.StringIO() plt.savefig(jpg_image_buffer) array = base64.b64encode(jpg_image_buffer.getvalue()) jpg_image_buffer.close() return array
と書いてresult.htmlに
<body> <img src="data:image/png;base64,{{ chart }}" /> </body>
と書いてresult.htmlをブラウザに表示させると
のように表示されました。横軸が全く年月(2016-04-10, 2016-10-05, 2016-10-10・・・)ではなくただの数字なのでなぜこうなってしまったのかわかりません。どのように直せば、横軸に年月を表示させられますか?横軸に2016-04-10, 2016-10-05, 2016-10-10, 2016-10-11, 2016-12-10 の順にグラフを取り、縦軸に100, 300, 200, 500, 400 の順に値を取りたいです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/10/25 13:47
2017/10/25 14:12
退会済みユーザー
2017/10/25 14:16
2017/10/25 15:22