我正在尝试在Django
上制作基于web的snake&;ladder游戏,为此我使用matplotlib
和mpld3
在网页上创建和显示我的游戏数据。你知道吗
我可以在网页上得到我的图像,但它是反向的。你知道吗
我在这个代码中哪里出错了?你知道吗
我的视图.py文件:
import matplotlib.image as mpimg
import mpld3 as mpld3
import numpy as np
import matplotlib.pyplot as plt
def home(request):
image = mpimg.imread('platform3.png')
figure = plt.figure(dpi=100)
subplot = figure.add_subplot(111)
subplot.set_xlim(0, 10)
subplot.set_ylim(0, 10)
subplot.imshow(image, extent=[0, 10, 0, 10])
canvas = FigureCanvas(figure)
response = django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
html_gen = 'graph.html'
with open(html_gen, 'w') as f:
f.write(mpld3.fig_to_html(figure))
f.write("Hello")
return render(request, html_gen)
我应该提供生成的html吗_生成.html文件也一样?你知道吗
只需将
[0, 0]
放在轴的左下角:请看一下^{} docs
更新:如何检查和设置默认
image.origin
值支票:
将
lower
设置为默认值(docs):再次检查:
相关问题 更多 >
编程相关推荐