Reputation: 31
My requirement is to plot one bar graph on a webpage with cherrypy and matplotlib. I am able to load the graph but cant get the coordinates onmouseover of plot. Can anybody suggest how can I get the coordinates.Do I have to use javascript or matplotlib can fulfill the requirement. The code looks simialr to this
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)
Upvotes: 1
Views: 311
Reputation: 35786
My requirement is to plot one bar graph on a webpage with cherrypy and matplotlib.
So, if that is your only requirement, you are close to your solution: create the plot file server-side and deliver it to the client.
However, it seems that this is not the only requirement (you really need to better express what you want to achieve when you ask others for help):
cant get the coordinates onmouseover of plot
This is something that has to happen client-side, i.e. within the browser. Hence, this is a task for JavaScript code executed by the browser in the context of your website.
So, if you are forced to using JavaScript anyway, maybe it would be better to serve the client (browser) only the data and let the plotting be handled by one of the many JavaScript plotting frameworks. That way, you save some load on the server (matplotlib plotting actually is pretty CPU intense) and also save bandwidth.
You may want to look at http://www.chartjs.org.
Upvotes: 2