Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1108053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:01:27+00:00 2026-05-17T02:01:27+00:00

I want to do a pie chart in matplotlib. This pie chart will be

  • 0

I want to do a pie chart in matplotlib.
This pie chart will be a representation of two variables: male and female.

That’s easy to do 🙂

What I would like to do next, I’m not even sure if it’s possible to do with matplotlib, I would like to make these two variables clickable so if I click on male, I would see another page with information about this, same thing with female.

Image map isn’t a solution since this variables may change in the future.

Anyone has any idea how to do this? If it’s possible with matplotlib or what program would you recommend.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:01:27+00:00Added an answer on May 17, 2026 at 2:01 am

    While it’s not really in a workably stable state yet, have a look at the html5 canvas backend for matplotlib. It looks interesting, anyway, and will probably be the best way to do this sort of thing (interactive webpage with a matplotlib plot) in the future.

    In the meantime, as @Mark suggested, it’s not too hard to dynamically generate an imagemap for the wedges of a pie plot.

    Here’s a rough example, that I’m sure you could adapt to whatever web framework you’re using.

    import matplotlib.pyplot as plt
    
    def main():
        # Make an example pie plot
        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.."""
        #-- Save the figure as an image and get image size ------------------------
        # Be sure to explictly set the dpi when saving the figure
        im_filename = 'temp.png'
        fig.savefig(im_filename, dpi=fig.dpi)
    
        # Get figure size...
        _, _, fig_width, fig_height = fig.bbox.bounds
    
        #-- Get the coordinates of each wedge as a string of x1,y2,x2,y2... -------
        coords = []
        for wedge in wedges:
            xy = wedge.get_verts() 
    
            # Transform to pixel coords
            xy = fig.get_transform().transform(xy) 
    
            # Format into coord string and convert to <0,0> in top left...
            xy = ', '.join(['%0.2f,%0.2f' % (x, fig_height - y) for x, y in xy])
            coords.append(xy)
    
        #-- Build web page --------------------------------------------------------
        header = """
        <html>
        <body>
        <img src="{0}" alt="Pie Chart" usemap="#pie_map" width="{1}" height="{2}" />
        """.format(im_filename, fig_width, fig_height)
    
        # Make the image map
        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>"""
    
        # Write to a file...
        with file(html_filename, 'w') as outfile:
            outfile.write(header + map + footer)
    
    if __name__ == '__main__':
        main()
    

    Edit: I just realized that you might not be referring to embedding the plot into a web page… (I assumed that you were from the “display another page” bit in your question.) If you want more of a desktop app, without having to mess with a “full” gui toolkit, you can do something like this:

    import matplotlib.pyplot as plt
    
    def main():
        # Make an example pie plot
        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))
    
        # Make wedges selectable
        for wedge in wedges:
            wedge.set_picker(True)
    
        fig.canvas.mpl_connect('pick_event', on_pick)
    
    if __name__ == '__main__':
        main()
    

    Which opens a browser window for a google image search of whatever the wedge is labeled as…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a report that contains a pie chart within it. I would want
I want to display the pie chart with an animation that will make it
i want to create one app which draw different charts like pie chart, line
I have a predefined pie chart like this: Ext.create('Ext.chart.Chart', { width : 450, height
I want to draw something like a pie chart segment filled with a certain
I want to show concentric pie chart from google chart api but the imageData
when i right click on the the Jframe this pie appears. what i want
I would like to create a horizontal proportional stacked bar chart, using R. My
I want to show pie chart of my category by percentage. How can I
I want to display bar chart and pie chart in my iPhone application please

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.