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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:10:44+00:00 2026-05-14T19:10:44+00:00

I have a 2-d array containing pairs of values and I’d like to make

  • 0

I have a 2-d array containing pairs of values and I’d like to make a boxplot of the y-values by different bins of the x-values. I.e. if the array is:

my_array = array([[1, 40.5], [4.5, 60], ...]])

then I’d like to bin my_array[:, 0] and then for each of the bins, produce a boxplot of the corresponding my_array[:, 1] values that fall into each box. So in the end I want the plot to contain number of bins-many box plots.

I tried the following:

min_x = min(my_array[:, 0])
max_x = max(my_array[:, 1])

num_bins = 3
bins = linspace(min_x, max_x, num_bins)
elts_to_bins = digitize(my_array[:, 0], bins)

However, this gives me values in elts_to_bins that range from 1 to 3. I thought I should get 0-based indices for the bins, and I only wanted 3 bins. I’m assuming this is due to some trickyness with how bins are represented in linspace vs. digitize.

What is the easiest way to achieve this? I want num_bins-many equally spaced bins, with the first bin containing the lower half of the data and the upper bin containing the upper half… i.e., I want each data point to fall into some bin, so that I can make a boxplot.

thanks.

  • 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-14T19:10:45+00:00Added an answer on May 14, 2026 at 7:10 pm

    Numpy has a dedicated function for creating histograms the way you need to:

    histogram(a, bins=10, range=None, normed=False, weights=None, new=None)
    

    which you can use like:

    (hist_data, bin_edges) = histogram(my_array[:,0], weights=my_array[:,1])
    

    The key point here is to use the weights argument: each value a[i] will contribute weights[i] to the histogram. Example:

    a = [0, 1]
    weights = [10, 2]
    

    describes 10 points at x = 0 and 2 points at x = 1.

    You can set the number of bins, or the bin limits, with the bins argument (see the official documentation for more details).

    The histogram can then be plotted with something like:

    bar(bin_edges[:-1], hist_data)
    

    If you only need to do a histogram plot, the similar hist() function can directly plot the histogram:

    hist(my_array[:,0], weights=my_array[:,1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects containing pairs of string labels and values, how
I have a 2D array containing all the Piece objects, each an instance of
Here is my issue. I have an array containing the name of cities that
I have two arrays containing the same elements, but in different orders, and I
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an array of hashes, and I want the unique values out of
In PHP I have an array containing 20 elements or more. The keys have
I have an array containing multiple integers, is there a common way for sorting
I have an array containing a Variable amount of results/entries. I use foreach as
I have an array containing names of items. I want to give the user

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.