データが一個もない時に画像がひび割れるのが理解できないです。画像をひび割れないで表示させたいです。
views.pyには
#coding:utf-8 def past_result(request): return render(request, 'past_result.html', {'chart': _make_img(request)}) def _make_img(): results = UserData.objects.filter(user=request.user).order_by('-consultation_date') if len(results)==0: return None xlist = [results[0].weight,results[1].weight,results[2].weight] ylist =[results[0].height,results[1].height,results[2].height] plt.plot(xlist, ylist,color="red",marker="x", markersize=15, markeredgewidth=4, linewidth=0) plt.xlim(0,180) plt.ylim(0, 230) plt.xlabel(u"身長") plt.ylabel(u"体重") plt.fill_between(x=[0,80],y1=0,y2=120, facecolor='yellow', alpha=0.08) plt.fill_between(x=[0,85], y1=0, y2=130, facecolor='yellow', 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には
<html lang="ja"> <img src="data:image/png;base64,{{ chart }}" width="700px" height="500px"/> </html>
と書きました。
results = UserData.objects.filter(user=request.user).order_by('-consultation_date')
のresultsに1件もデータが入っていない時、past_result.htmlのimgの画像が以下のようにひび割れて表示されます。
ひび割れずに、何もデータがプロットされていない状態で画像を表示させたいです。
matplotlibではデータが1個もなくplt.plotすると画像がひび割れてしまうのでしょうか?どのように直せば何もデータがない時に画像がひび割れずに表示できるでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。