0

Django私が使用matplotlibしている で Web ベースのヘビとはしごゲームmpld3を作成し、Web ページにゲームデータを作成して表示しようとしています。

Web ページで画像を取得できますが、反転しています。

このコードのどこが間違っていますか?

私のviews.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_gen.html ファイルも提供する必要がありますか?

4

1 に答える 1

1

[0, 0]を軸の左下隅に配置するだけです:

subplot.imshow(image, extent=[0, 10, 0, 10], origin='lower')

ドキュメントをご覧くださいimshow()

更新: デフォルトimage.origin値を確認して設定する方法

  1. 小切手:

    >>> import matplotlib as mpl
    >>> print(mpl.rcParams['image.origin'])
    upper
    
  2. lowerデフォルト値として設定( docs ):

    $ echo "image.origin : lower" >> .config/matplotlib/matplotlibrc
    
  3. 再び確かめる:

    >>> import matplotlib as mpl
    >>> print(mpl.rcParams['image.origin'])
    upper
    
于 2016-12-06T23:31:44.847 に答える