グラフの色が重なってしまいます。
def past_result(request): return render(request, 'past_result.html', {'chart': _view_plot(request)}) def _view_plot(request): plt.plot(100, 110,color="black",marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.plot(120,130,color="black", marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.plot(140,150,color="black", marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.plot(130, 140,color="black", marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.plot(155, 160,color="black", marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.legend() plt.xlim(0,200) plt.ylim(0, 250) plt.xlabel(u"身長") plt.ylabel(u"体重") plt.fill_between(x=[0,80],y1=0,y2=120, facecolor="red", alpha=0.2) plt.fill_between(x=[0,85], y1=0, y2=130, facecolor="blue", alpha=0.2) plt.fill_between(x=[0,90], y1=0, y2=140, facecolor="yellow", alpha=0.2) plt.fill_between(x=[0,100], y1=0, y2=160, facecolor="green", alpha=0.2) plt.fill_between(x=[0,110], y1=0, y2=180, facecolor="purple", alpha=0.2) plt.fill_between(x=[0,130], y1=0, y2=210, facecolor="white", alpha=0.2) jpg_image_buffer = cStringIO.StringIO() plt.savefig(jpg_image_buffer) array = base64.b64encode(jpg_image_buffer.getvalue()) jpg_image_buffer.close() return array
とコードを書いて
past_result.htmlには
<img src="data:image/png;base64,{{ chart }}" width="700px" height="500px" />
と書きました。
past_resultメソッドを実行するとpast_result.htmlの画像が
のようになり、編みかけした色が赤・青・黄色・緑・紫・白をはっきり別れるはずが全部の色が重なってしまっています。
理想のアウトプットは
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。