我使用python 3.4和Django 1.8.我想在Django模板中"打印"matplotlib结果.我几天前就达成了这个,所以我继续使用我的Django App的其他东西.现在,我不知道为什么,我要向朋友展示结果,而我的模板带有matplotlib图,现在显示了一个很大的代码!我不知道为什么会发生这种情况,因为我的观点在显示正确的图形时没有任何变化!请帮我!
这是我的看法!
from django.shortcuts import render
from matplotlib import pylab
from pylab import *
import PIL
import PIL.Image
import io
from io import *
def graphic(request):
pos = arange(10)+ 2
barh(pos,(1,2,3,4,5,6,7,8,9,10),align = 'center')
yticks(pos,('#hcsm','#ukmedlibs','#ImmunoChat','#HCLDR','#ICTD2015','#hpmglobal','#BRCA','#BCSM','#BTSM','#OTalk'))
xlabel('Popularity')
ylabel('Hashtags')
title('Hashtags')
subplots_adjust(left=0.21)
buffer = io.BytesIO()
canvas = pylab.get_current_fig_manager().canvas
canvas.draw()
graphIMG = PIL.Image.fromstring('RGB', canvas.get_width_height(), canvas.tostring_rgb())
graphIMG.save(buffer, "PNG")
content_type="Image/png"
buffercontent=buffer.getvalue()
graphic = (buffercontent ,content_type)
pylab.close()
return render(request, 'graphic.html',{'graphic':graphic})
Run Code Online (Sandbox Code Playgroud)
当然,在我的graphic.html中,一个名为{{graphic}}的变量在blockcontent中!
这在我的模板中显示了正确的结果!发生什么事?现在,有时当我运行我的模板时,它会显示一个很大的代码,或者只是告诉我这个django错误:
异常值:
主线程不在主循环中
异常位置:blit中的C:\ Python34\lib\site-packages\matplotlib\backends\tkagg.py,第17行
救命!
我是 python 和 matplotlib 的新手。我有一个项目,我需要使用 matplotlib 在 Tkinter GUI 中创建一个图形。我发现并使用了这个代码:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 …Run Code Online (Sandbox Code Playgroud) 您好我一直在寻找删除或重命名手机内部存储中的特定文件的方法.具体来说,我的目标是waze文件夹中的文件,它们位于内部存储的根文件夹中.正如我所说,我寻找更多关于此的信息,但没有任何对我有用,所以我认为我的错误可能在我正在使用的路径中.这是我的代码:
重新命名:
file_Path = "/data/data/waze"
File from = new File(file_Path, "currentFileName");
File to = new File(file_Path, "newFilename");
from.renameTo(to); //this method returns me False
Run Code Online (Sandbox Code Playgroud)
删除:
file_Path ="/data/data/waze/file"
File file = new File(file_Path);
boolean deleted = file.delete();
Run Code Online (Sandbox Code Playgroud)
我尝试了很多方法来做到这一点,但这是我认为接近它的方法.所以如果你们中的任何人都能指出我的错误,我会感谢你们!来自哥斯达黎加的拥抱!