How to use Matplotlib in Django?

前端 未结 2 760
一整个雨季
一整个雨季 2020-12-01 04:29

From some examples from the Internet I made the test code below. It works!

... BUT if I reload the page, the pie will draw itself with the same image. Some parts ge

2条回答
  •  囚心锁ツ
    2020-12-01 05:17

    You need to remove the num parameter from the figure constructor and close the figure when you're done with it.

    import matplotlib.pyplot
    
    def test_matplotlib(request):
        f = figure(figsize=(6,6))
        ....
        matplotlib.pyplot.close(f)
    

    By removing the num parameter, you'll avoid using the same figure at the same time. This could happen if 2 browsers request the image at the same time. If this is not an issue, another possible solution is to use the clear method, i.e. f.clear().

提交回复
热议问题