我的要求是用cherrypy和matplotlib在网页上绘制一个条形图。我可以加载图形,但无法获得鼠标上方的坐标 情节。谁能告诉我怎么才能得到坐标。做我必须用javascript或者matplotlib来满足这个要求。 代码看起来与此类似
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class HelloWorld:
def index(self):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
fig.savefig('test.png')
return ''' <img src="test.png" width="640" height="480" border="0" /> '''
index.exposed = True
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld(), config=tutconf)
else:
cherrypy.tree.mount(HelloWorld(), config=tutconf)
因此,如果这是您唯一的需求,那么您就接近您的解决方案:创建打印文件服务器端并将其交付给客户机。在
然而,这似乎不是唯一的要求(当你向别人求助时,你真的需要更好地表达你想要达到的目标):
这是必须在客户端(即在浏览器中)发生的事情。因此,这是一个由浏览器在网站上下文中执行的JavaScript代码的任务。在
因此,如果您被迫使用JavaScript,那么最好只为客户端(浏览器)提供数据,并让绘图由众多JavaScript绘图框架之一处理。这样,您可以在服务器上节省一些负载(matplotlib绘图实际上相当占用CPU资源),还可以节省带宽。在
您可能需要查看http://www.chartjs.org。在
相关问题 更多 >
编程相关推荐