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 9252397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:56:06+00:00 2026-06-18T10:56:06+00:00

I have a matplotlib hexbin embedded in a GTK.Window that graphs some data (x,y).

  • 0

I have a matplotlib hexbin embedded in a GTK.Window that graphs some data (x,y). I want the plot to update when new data is received (via UDP). I am having some trouble though.

I can get it to work in several different ways, but none have been “efficient” (Meaning – redrawing the plot takes too long). I looked here and attempted to model my hexbin after the suggested answer but could not get this to work at all. I keep receiving the following error:

TypeError: 'PolyCollection' object is not iterable.

I’m guessing that hexbins cannot be update in the same way as standard plots.

Sample Code:

class graph:
    def __init__(self):
        self.window = gtk.Window()
        self.figure = plt.figure()
        self.ax = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self.figure)
        self.window.add(self.canvas)

        self.graph = None

    def plot(self, xData, yData):
        if len(xData) > 1 and len(yData) > 1:
            self.graph, = self.ax.hexbin(self.xData, self.yData) 
            ###############################################
            ####This is where the code throws the error####

    def update(self, xData, yData):
        self.graph.set_xdata(np.append(self.graph.get_xdata(), xData))
        self.graph.set_ydata(np.append(self.graph.get_ydata(), yData))
        self.figure.canvas.draw()

The code is used like this:

graph = graph()
graph.plot(someXData, someYData)
# when new data is received
graph.update(newXData, newYData)

This is just a very small example of how I’m using the code. I don’t have much experience with matplotlib so there is chance I could be going about this completely wrong. (which is most likely what I am doing)

So my ultimate question is – How do you update a matplotlib hexbin plot?


Edit: Thanks to danodonovan’s answer, I altered my code and removed the ‘,’ after self.graph = self.ax.hexbin(...)

The new error thrown is: AttributeError: 'PolyCollection' object has no attribute 'set_xdata'

  • 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-06-18T10:56:08+00:00Added an answer on June 18, 2026 at 10:56 am

    I don’t think that this can be done currently, hexbin converts list of x,y -> a collections of polygons. The polyCollection is just a list of verticies, edges, and face colors, I don’t think it carries any semantic information about how it was generated.

    The best approach is to nuke the old hexbin and replace it with a new one.

    If you really want to be able to update in-place either use a square 2d histogram (so you can use imshow), or you can modify hexbin to return a list of patches (instead of a polyCollection) and keep track of the binning your self.

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

Sidebar

Related Questions

I have a graph, computed from some data, drawn in matplotlib. I want to
I have written a program in Python that draws some graphs using matplotlib and
I have a matplotlib code that generates a simple 2D chart. I want to
Say that I have two figures in matplotlib, with one plot per figure: import
I have a matplotlib figure that I want to be able to switch between
I have a plot in matplotlib with multiple subplots(axes), and I want to annotate
I have a program that receives serial data and uses matplotlib to graph it
I have a few boxplots in matplotlib that I want to zoom in on
I have some complex graphs made using matplotlib. Saving them to a pdf using
I have an embedded matplotlib plot in a PyQt4 application. This is the plotting

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.