While it is not yet in a stable stable state, look at the html5 canvas backend for matplotlib . Anyway, this looks interesting, and probably this is the best way to do such a thing (an interactive webpage with matplotlib graphics) in the future.
In the meantime, as @Mark suggested, itβs not too difficult to dynamically generate an imagination map for the wedges of the pie section.
Here is an example: that I am sure that you can adapt to any web infrastructure that you use.
import matplotlib.pyplot as plt
def main():
fig = plt.figure()
ax = fig.add_subplot(111)
labels = ['Beans', 'Squash', 'Corn']
wedges, plt_labels = ax.pie([20, 40, 60], labels=labels)
ax.axis('equal')
make_image_map(fig, wedges, labels, 'temp.html')
def make_image_map(fig, wedges, labels, html_filename):
"""Makes an example static html page with a image map of a pie chart.."""
im_filename = 'temp.png'
fig.savefig(im_filename, dpi=fig.dpi)
_, _, fig_width, fig_height = fig.bbox.bounds
coords = []
for wedge in wedges:
xy = wedge.get_verts()
xy = fig.get_transform().transform(xy)
xy = ', '.join(['%0.2f,%0.2f' % (x, fig_height - y) for x, y in xy])
coords.append(xy)
header = """
<html>
<body>
<img src="{0}" alt="Pie Chart" usemap="#pie_map" width="{1}" height="{2}" />
""".format(im_filename, fig_width, fig_height)
map = '<map name="pie_map">\n'
for label, xy in zip(labels, coords):
href = 'http://images.google.com/images?q={0}'.format(label)
area = '<area shape="poly" coords="{0}" href="{1}" alt="{2}" />'
area = area.format(xy, href, label)
map += ' ' + area + '\n'
map += '</map>\n'
footer = """
</body>
</html>"""
with file(html_filename, 'w') as outfile:
outfile.write(header + map + footer)
if __name__ == '__main__':
main()
: , -... ( , " " .) , "" gui, - :
import matplotlib.pyplot as plt
def main():
fig = plt.figure()
ax = fig.add_subplot(111)
labels = ['Beans', 'Squash', 'Corn']
wedges, plt_labels = ax.pie([20, 40, 60], labels=labels)
ax.axis('equal')
make_picker(fig, wedges)
plt.show()
def make_picker(fig, wedges):
import webbrowser
def on_pick(event):
wedge = event.artist
label = wedge.get_label()
webbrowser.open('http://images.google.com/images?q={0}'.format(label))
for wedge in wedges:
wedge.set_picker(True)
fig.canvas.mpl_connect('pick_event', on_pick)
if __name__ == '__main__':
main()
Google, , ...