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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:56:50+00:00 2026-05-26T08:56:50+00:00

I would like to draw histogram using matplotlib. However, due to the huge data(a

  • 0

I would like to draw histogram using matplotlib. However, due to the huge data(a list containing about 100,000 numbers) I sent to the hist() function, error will arise when draw two figures. But it goes smoothly while only drawing either of the two plots. Could anyone help me to deal with this? Thanks in advance.

Here is the simplified code to show the error:

f_120 = plt.figure(1)
plt.hist(taccept_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'b', label = 'accepted answer')
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first 2 hrs)')
plt.ylim(0,1)
plt.xlim(0,120)
f_120.show()
f_120.savefig('7month_0_120.png', format = 'png' )
plt.close()

f_2640 = plt.figure(2)
plt.hist(taccept_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'b', label = 'accepted answer')
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 240, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '4 hours')
plt.axvline(x = 1440, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 day')
plt.legend(loc= 4)

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first 48)')
plt.ylim(0,1)
plt.xlim(0,2640)
f_2640.show()
f_2640.savefig('7month_0_2640.png', format = 'png' )

The following is the error detail:

plt.hist(tfirst_list, bins=6000000, normed = True, histtype =”step”, cumulative = True, color = ‘g’,label = ‘first answer’)

File “C:\software\Python26\lib\site-packages\matplotlib\pyplot.py”, line 2160, in hist
ret = ax.hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, **kwargs)

File “C:\software\Python26\lib\site-packages\matplotlib\axes.py”, line 7775, in hist
closed=False, edgecolor=c, fill=False) )

File “C:\software\Python26\lib\site-packages\matplotlib\axes.py”, line 6384, in fill
for poly in self._get_patches_for_fill(*args, **kwargs):

File “C:\software\Python26\lib\site-packages\matplotlib\axes.py”, line 317, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):

File “C:\software\Python26\lib\site-packages\matplotlib\axes.py”, line 304, in _plot_args
seg = func(x[:,j%ncx], y[:,j%ncy], kw, kwargs)

File “C:\software\Python26\lib\site-packages\matplotlib\axes.py”, line 263, in _makefill
(x[:,np.newaxis],y[:,np.newaxis])),

File “C:\software\Python26\lib\site-packages\numpy\core\shape_base.py”, line 270, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)

MemoryError

  • 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-26T08:56:50+00:00Added an answer on May 26, 2026 at 8:56 am

    As others have noted, six million bins doesn’t sound very useful. But a simple thing would be to reuse the same figure: since the only plot elements that change are things other than the histograms, try something like this:

    vline1 = plt.axvline(...)
    vline2 = plt.axvline(...)
    lgd = legend()
    

    and after the savefig don’t close the figure and plot new histograms, instead reuse it, changing what needs to be changed:

    # change vline1 and vline2 positions and labels
    vline1.set_data([240,240],[0,1])
    vline1.set_label('new label')
    vline2.set_data(...)
    vline2.set_label(...)
    # remove old legend, replace with new
    lgd.remove()
    lgd = plt.legend(loc=4)
    plt.xlabel('new xlabel')
    # etc
    

    Finally call savefig again with the new filename.

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

Sidebar

Related Questions

Would like to get a list of advantages and disadvantages of using Stored Procedures.
I am making a GUI program using gtkmm. I would like to draw some
I'm displaying a histogram for a grayscale image and I would like to draw
Instead of setting image using 'background' property, I would like to draw the image
I would like to draw a table using System.Drawings, and then fill cells with
I would like to draw an icon/bmp into a subitem of a TListView using
I would like to draw some lines using Path. It always show me error
I would like to draw on a CGContext by using tiles from CGImage that
I would like to draw lines (of arbitrary position and length) onto a surface
I would like to draw some shapes on a JPanel by overriding paintComponent .

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.