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

  • SEARCH
  • Home
  • 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 8951745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:44:05+00:00 2026-06-15T13:44:05+00:00

I use matplotlib’s method hexbin to compute 2d histograms on my data. But I

  • 0

I use matplotlib’s method hexbin to compute 2d histograms on my data.
But I would like to get the coordinates of the centers of the hexagons in order to further process the results.

I got the values using get_array() method on the result, but I cannot figure out how to get the bins coordinates.

I tried to compute them given number of bins and the extent of my data but i don’t know the exact number of bins in each direction. gridsize=(10,2) should do the trick but it does not seem to work.

Any idea?

  • 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-15T13:44:06+00:00Added an answer on June 15, 2026 at 1:44 pm

    I think this works.

    from __future__ import division
    import numpy as np
    import math
    import matplotlib.pyplot as plt
    
    def generate_data(n):
        """Make random, correlated x & y arrays"""
        points = np.random.multivariate_normal(mean=(0,0),
            cov=[[0.4,9],[9,10]],size=int(n))
        return points
    
    if __name__ =='__main__':
    
        color_map = plt.cm.Spectral_r
        n = 1e4
        points = generate_data(n)
    
        xbnds = np.array([-20.0,20.0])
        ybnds = np.array([-20.0,20.0])
        extent = [xbnds[0],xbnds[1],ybnds[0],ybnds[1]]
    
        fig=plt.figure(figsize=(10,9))
        ax = fig.add_subplot(111)
        x, y = points.T
        # Set gridsize just to make them visually large
        image = plt.hexbin(x,y,cmap=color_map,gridsize=20,extent=extent,mincnt=1,bins='log')
        # Note that mincnt=1 adds 1 to each count
        counts = image.get_array()
        ncnts = np.count_nonzero(np.power(10,counts))
        verts = image.get_offsets()
        for offc in xrange(verts.shape[0]):
            binx,biny = verts[offc][0],verts[offc][1]
            if counts[offc]:
                plt.plot(binx,biny,'k.',zorder=100)
        ax.set_xlim(xbnds)
        ax.set_ylim(ybnds)
        plt.grid(True)
        cb = plt.colorbar(image,spacing='uniform',extend='max')
        plt.show()
    

    enter image description here

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

Sidebar

Related Questions

I would like to use matplotlib to generate a number of PDF files. My
I have a working Python 2.6 code using matplotlib, and would like to get
I would like to use Matplotlib to generate a scatter plot with a huge
If I use a Matplotlib DateFormatter, like this: mydateformatter = DateFormatter(%b %d %I:%M %p,
I would like to use an IPython notebook as a way to interactively analyze
When I use matplotlib's imshow() method to represent a small numpy matrix, it ends
I need to use matplotlib for a school project and cannot get it installed
I use matplotlib to create a figure with 4 sub-plots in it. I would
I'd like to use Matplotlib and pyplot to generate an svg image to be
I would like to store the image generated by matplotlib in a variable raw_data

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.