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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:20:16+00:00 2026-05-23T04:20:16+00:00

I have a large 2D dataset where I want to associate to each X,Y

  • 0

I have a large 2D dataset where I want to associate to each X,Y pair a color and plot it with matplotlib. I am talking about 1000000 points. I wonder what is the best approach in terms of performance (speed) and if you could point to some example

  • 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-23T04:20:17+00:00Added an answer on May 23, 2026 at 4:20 am

    If you’re dealing with a regular grid, just treat it as an image:

    import numpy as np
    import matplotlib.pyplot as plt
    
    nrows, ncols = 1000, 1000
    z = 500 * np.random.random(nrows * ncols).reshape((nrows, ncols))
    
    plt.imshow(z, interpolation='nearest')
    plt.colorbar()
    plt.show()
    

    enter image description here

    If you have randomly ordered x,y,z triplets that make up a regular grid, then you’ll need to grid them.

    Essentially, you might have something like this:

    import numpy as np 
    import matplotlib.pyplot as plt
    
    # Generate some data
    nrows, ncols = 1000, 1000
    xmin, xmax = -32.4, 42.0
    ymin, ymax = 78.9, 101.3
    
    dx = (xmax - xmin) / (ncols - 1)
    dy = (ymax - ymin) / (ncols - 1)
    
    x = np.linspace(xmin, xmax, ncols)
    y = np.linspace(ymin, ymax, nrows)
    x, y = np.meshgrid(x, y)
    
    z = np.hypot(x - x.mean(), y - y.mean())
    x, y, z = [item.flatten() for item in (x,y,z)]
    
    # Scramble the order of the points so that we can't just simply reshape z
    indicies = np.arange(x.size)
    np.random.shuffle(indicies)
    x, y, z = [item[indicies] for item in (x, y, z)]
    
    # Up until now we've just been generating data...
    # Now, x, y, and z probably represent something like you have.
    
    # We need to make a regular grid out of our shuffled x, y, z indicies.
    # To do this, we have to know the cellsize (dx & dy) that the grid is on and
    # the number of rows and columns in the grid. 
    
    # First we convert our x and y positions to indicies...
    idx = np.round((x - x.min()) / dx).astype(np.int)
    idy = np.round((y - y.min()) / dy).astype(np.int)
    
    # Then we make an empty 2D grid...
    grid = np.zeros((nrows, ncols), dtype=np.float)
    
    # Then we fill the grid with our values:
    grid[idy, idx] = z
    
    # And now we plot it:
    plt.imshow(grid, interpolation='nearest', 
            extent=(x.min(), x.max(), y.max(), y.min()))
    plt.colorbar()
    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 have a dataset consisting of a large collection of points in three dimensional
Assume I have a large dataset and I want to run a like function
I have a large dataset with documents that sometimes cross-reference each other, sometimes do
I have a large dataset (202k points). I know that there are 8 values
I have a large typed dataset which I want to partially fill for unit
Scenario: I have a large dataset, with each entry containing a location (x,y -
I have a very large dataset - millions of records - that I want
I have a fairly large dataset (by my standards) and I want to create
I have a large data set and I want to write a custom merge
I have a large dataset that load in with a fill method on page

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.